Qt + Python + OpenCV图标替换工具 之 Qt界面设计(四)

目录

 

上一篇博文

程序的下载地址以及源码

Qt界面设计


 

上一篇博文

Qt + Python + OpenCV图标替换工具 之 Python调用dll(三)

https://blog.csdn.net/qq78442761/article/details/85941704

 

 

程序的下载地址以及源码

源码已经打包:

运行版本(release版本(编译好)下载地址如下):

https://download.csdn.net/download/qq78442761/10899496

 

源码下载地址如下:

https://download.csdn.net/download/qq78442761/10899518

 

Qt界面设计

Qt界面结构如下:

 

界面运行截图如下:

 

这里把使用自定义界面,就是把系统的标题栏和边框全部去掉!

    setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);

然后再使用重写下面三个事件:

    void mouseMoveEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
    void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
    void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;

重写

 void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;

可以实现制作圆角界面:

void PicWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QBrush(Qt::white));
    painter.setPen(Qt::black);
    QRect rect = this->rect();
    rect.setWidth(rect.width() - 1);
    rect.setHeight(rect.height() - 1);
    painter.drawRoundedRect(rect, 15, 15);

    QWidget::paintEvent(event);
}

 

这里再说明最后一点:

也就是 “用户提示” 手册,这里使用了QGraphicsView框架!

这里是构造一个界面,然后最大话,在吧item放到界面上即可:

ShowGraphicsView::ShowGraphicsView(QWidget *parent) : QGraphicsView(parent)
{
    this->setWindowTitle("用户使用手册");
    setStyleSheet("background: transparent;border:0px");
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setRenderHints(renderHints() | QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    setAttribute(Qt::WA_TranslucentBackground);

    m_scene = new QGraphicsScene;
    this->setScene(m_scene);



    this->setGeometry(0, 0, 100, 100);
}

 

通过添加item实现界面上显示文字,如下图:

 

void ShowGraphicsView::addTextItem(const int &posX, const int &posY, const QString &text)
{
    TipGraphicsItem *item = new TipGraphicsItem;
    item->setPos(posX, posY);
    item->setShowText(text);
    m_scene->addItem(item);
}

 

添加文字的源码如下:

void PicWidget::manualBtnClicked()
{
    QRect screenRect = QApplication::desktop()->screenGeometry();
    m_showGraphicsView->fixSceneWindow(screenRect.width(), screenRect.height());

    m_showGraphicsView->show();
    m_showGraphicsView->addTextItem(pos().x() + ui->iconLabel->pos().x() - 40
                                    , pos().y() + ui->iconLabel->pos().y() - 15, "程序的icon");

    m_showGraphicsView->addTextItem(pos().x() + ui->closeLabel->pos().x() - 40
                                    , pos().y() + ui->closeLabel->pos().y() - 15, "程序的关闭按钮");

    m_showGraphicsView->addTextItem(pos().x() + ui->choosePicLabel->pos().x() - 40
                                    , pos().y() + ui->choosePicLabel->pos().y() + 75, "选着一张图片");

    m_showGraphicsView->addTextItem(pos().x() + ui->chooseColorLabel->pos().x() - 20
                                    , pos().y() + ui->chooseColorLabel->pos().y() + 75, "选着图片后选着一个颜色");

    m_showGraphicsView->addTextItem(pos().x() + ui->productLabel->pos().x()
                                    , pos().y() + ui->productLabel->pos().y() + 75, "调用py生成图片并读取");

    m_showGraphicsView->addTextItem(pos().x() + ui->changeProLabel->pos().x() - 10
                                    , pos().y() + ui->changeProLabel->pos().y() + 80, "转化算法,生成其他图片");

    m_showGraphicsView->addTextItem(pos().x() + ui->howToUseLabel->pos().x() - 40
                                    , pos().y() + ui->howToUseLabel->pos().y() + 90, "用户使用手册");

    m_showGraphicsView->addTextItem(pos().x() + ui->genLabel5->pos().x() + 90
                                    , pos().y() + ui->genLabel5->pos().y() + 90, "生成图片的位置,右击保存");

    QEventLoop loop;
    QTimer::singleShot(5 * 1000, &loop, SLOT(quit()));
    loop.exec();

    m_showGraphicsView->hide();
    m_showGraphicsView->clearItem();
}

 

 

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页