1. 程式人生 > >Qt淺談之五十介面自定義

Qt淺談之五十介面自定義

一、簡介

      Qt自帶的介面不利於樣式的調整和美化,自定義介面便於設計風格。

二、詳解

1、程式碼

(1)pagenumbercontrol.h

#ifndef PAGENUMBERCONTROL_H
#define PAGENUMBERCONTROL_H

#include <QWidget>
#include "custombtn.h"

#ifndef ABSTRACT
  #define ABSTRACT =0
#endif

//usage:IPageNumberControl *app = new PageNumberControl(this);
class IPageNumberControl : public QWidget
{
    Q_OBJECT
public:
    virtual ~IPageNumberControl(){};
protected:
    IPageNumberControl(QWidget *parent = 0):QWidget(parent){};

public:
    virtual void setCurrentPage(int currentPageNumber) ABSTRACT;
    virtual void setTotalPage(int totalPageNumber) ABSTRACT;
    virtual void setCurrentAndTotalPage(int currentPageNumber, int totalPageNumber) ABSTRACT;
    virtual void setBackgroundColor(const QColor & color) ABSTRACT;

signals:
    void currentPageChanged(int);
};
class PageNumberControl : public IPageNumberControl
{
    Q_OBJECT
public:
    explicit PageNumberControl(QWidget *parent = 0);
    ~PageNumberControl();
public:
    void setCurrentPage(int currentPageNumber);
    void setTotalPage(int totalPageNumber);
    void setCurrentAndTotalPage(int currentPageNumber, int totalPageNumber);
    void setBackgroundColor(const QColor & color);

protected:
    void paintEvent(QPaintEvent *event);

private:
    void updatePageNumber();

private slots:
    void slotForwardPage();
    void slotBackwardPage();

private:
    QLabel *currentPageLabel;
    QLabel *middleLabel;
    QLabel *totalPageLabel;

    CustomBtn *forwardBtn;
    CustomBtn *backwardBtn;

    QPoint dragPosition;

    int _currentPageNumber;
    int _totalPageNumber;
    QColor backgroundColor;
};

#endif // PAGENUMBERCONTROL_H
(2)pagenumbercontrol.cpp
#include <QtGui>
#include "pagenumbercontrol.h"

PageNumberControl::PageNumberControl(QWidget *parent)
    : IPageNumberControl(parent)
{
 //   setAutoFillBackground(true);
    backgroundColor = QColor(0xFF,0xFF,0xFF,0xFF);
    _currentPageNumber = 1;
    _totalPageNumber = 1;

    setStyleSheet("QLabel{font-family:arial;font-size:14px; color:#19649F;}");
    currentPageLabel = new QLabel(this);
    middleLabel = new QLabel(tr("/"), this);
    totalPageLabel = new QLabel(this);

    forwardBtn = new CustomBtn(this);
    forwardBtn->SetImgs(":/images/btn15_bg_hover.png", ":/images/btn15_bg.png", ":/images/btn15_bg_disable.png", "");
    forwardBtn->resize(35, 15);
    forwardBtn->move(0,0);
    forwardBtn->setText("<", Qt::white, Qt::white, QFont("verdana", 10, QFont::Normal));
    connect(forwardBtn, SIGNAL(clicked()), this, SLOT(slotForwardPage()));

    backwardBtn = new CustomBtn(this);
    backwardBtn->SetImgs(":/images/btn15_bg_hover.png", ":/images/btn15_bg.png", ":/images/btn15_bg_disable.png", "");
    backwardBtn->setText(">", Qt::white, Qt::white, QFont("verdana", 10, QFont::Normal));
    backwardBtn->resize(35, 15);
    backwardBtn->move(18,0);
    connect(backwardBtn, SIGNAL(clicked()), this, SLOT(slotBackwardPage()));

    updatePageNumber();

    resize(95, 15);
    setWindowFlags(Qt::FramelessWindowHint);
}

PageNumberControl::~PageNumberControl()
{

}

void PageNumberControl::setCurrentPage(int currentPageNumber)
{
    if (currentPageNumber > _totalPageNumber) {    //超出最大頁
        _currentPageNumber = _totalPageNumber;
    }
    else if (currentPageNumber < 1) {              //設定超出最小範圍
        _currentPageNumber = 1;
    }
    else {
        _currentPageNumber = currentPageNumber;    //正常
    }
    updatePageNumber();
}

void PageNumberControl::setTotalPage(int totalPageNumber)       //總頁優先順序高
{
    if (totalPageNumber < 1) {                          //總頁設定超出最小範圍
        if (_currentPageNumber <= 1)  _totalPageNumber = 1;
        else _totalPageNumber = _currentPageNumber;
    }
    else if (totalPageNumber < _currentPageNumber){     //總頁設定小於當前頁
        _totalPageNumber = totalPageNumber;
        _currentPageNumber = totalPageNumber;

    }
    else {
        _totalPageNumber = totalPageNumber;             //正常
    }
    updatePageNumber();
}

void PageNumberControl::setCurrentAndTotalPage(int currentPageNumber, int totalPageNumber)
{
    if (currentPageNumber > totalPageNumber)    //當前頁範圍過大,以總頁數為優先順序
        _currentPageNumber = totalPageNumber;
    setTotalPage(totalPageNumber);
    setCurrentPage(currentPageNumber);

}
void PageNumberControl::slotForwardPage()              //向前翻頁
{
    _currentPageNumber--;
    emit currentPageChanged(_currentPageNumber);      //傳送頁面改變訊號
    updatePageNumber();
}

void PageNumberControl::slotBackwardPage()             //向後翻頁
{
    _currentPageNumber++;
    emit currentPageChanged(_currentPageNumber);      //傳送頁面改變訊號
    updatePageNumber();
}
void PageNumberControl::updatePageNumber()
{
    //翻頁更新
    if (_currentPageNumber <= 1) {
        forwardBtn->enabled(false);
    }
    else {
        forwardBtn->enabled(true);
    }
    if (_currentPageNumber >= _totalPageNumber) {
        backwardBtn->enabled(false);
    }
    else {
        backwardBtn->enabled(true);
    }
    QFontMetrics currentMetrics(currentPageLabel->font());
    int currentTextWidth = currentMetrics.width(QString::number(_currentPageNumber));
    int currentTextHeight = currentMetrics.height();
    QFontMetrics totalMetrics(totalPageLabel->font());
    int totalTextWidth = totalMetrics.width(QString::number(_totalPageNumber));
    int totalTextHeight = totalMetrics.height();

    currentPageLabel->resize(currentTextWidth, currentTextHeight);
    totalPageLabel->resize(totalTextWidth + 1, totalTextHeight);

    currentPageLabel->move(38, 0);
    middleLabel->move(39 + currentTextWidth, 0);
    totalPageLabel->move(44 + currentTextWidth, 0);

    currentPageLabel->setText(QString::number(_currentPageNumber));
    totalPageLabel->setText(QString::number(_totalPageNumber));
}
void PageNumberControl::setBackgroundColor(const QColor &color)
{
    backgroundColor = color;
    update();
}
void PageNumberControl::paintEvent(QPaintEvent *event)
{
    QPalette pal = palette();
    pal.setColor(QPalette::Background, backgroundColor);
    setPalette(pal);

    QWidget::paintEvent(event);
}
(3)selecttemplate.h
#ifndef SELECTTEMPLATE_H
#define SELECTTEMPLATE_H

#include <QtGui>
#include "custombtn.h"
#include "pagenumbercontrol.h"

class SelectTemplate : public QDialog
{
    Q_OBJECT
public:
    explicit SelectTemplate(QWidget *parent = 0);

protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void paintEvent(QPaintEvent *event);

private:
    bool bPressFlag;
    QPoint dragPosition;

    QPixmap backGroundPix;
    CustomBtn *closeBtn;
    CustomBtn *confirmBtn;
    QButtonGroup *group;

    PageNumberControl *turnPage;

signals:

public slots:
    void slotButtonGroup(QAbstractButton * button);
    void slotButtonGroup(int id);
    void slotConfirmBtn();
};

#endif // SELECTTEMPLATE_H
(4)selecttemplate.cpp
#include "selecttemplate.h"

SelectTemplate::SelectTemplate(QWidget *parent) :
    QDialog(parent), bPressFlag(false)
{
    /***************setup********************/
    setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    setAutoFillBackground(false);
    QPalette pal = palette();
    pal.setColor(QPalette::Background, QColor(0xFF,0xFF,0xFF,0xFF));
    setPalette(pal);

    backGroundPix = QPixmap(":/images/client_bg.png");
    resize(backGroundPix.width(),  backGroundPix.height());

    confirmBtn = new CustomBtn(this);
    confirmBtn->SetImgs(":/images/btn120_bg_hover.png", ":/images/btn120_bg.png"
                        , "", ":/images/btn120_bg_hover.png");
    confirmBtn->setText(QString(tr("<<確認選擇")));
    confirmBtn->move(185, 325);
    connect(confirmBtn, SIGNAL(clicked()), this, SLOT(slotConfirmBtn()));

    QListWidget *applistWidget = new QListWidget(this);
    applistWidget->move(150, 60);
    applistWidget->resize(280,250);
    applistWidget->setStyleSheet("background-color:#ffffff;border-top: 1px solid #949494;"
                                 "border-right: 1px solid #949494;border-bottom:1px solid #949494;");
    applistWidget->setFocusPolicy(Qt::NoFocus);
    //applistWidget->setEnabled(false);
    QListWidgetItem *softWareOne = new QListWidgetItem;
    softWareOne->setIcon(QIcon(":/images/appList_icon.png"));
    softWareOne->setText(tr("ADobe Dreamweaver CS6"));
    softWareOne->setSizeHint(QSize(35,32));
    applistWidget->addItem(softWareOne);
    QListWidgetItem *softWareTwo = new QListWidgetItem;
    softWareTwo->setIcon(QIcon(":/images/appList_icon.png"));
    softWareTwo->setText(tr("Flash Player"));
    softWareTwo->setSizeHint(QSize(35,32));
    applistWidget->addItem(softWareTwo);

    group = new QButtonGroup(this);
    for(int i = 0;i < 7; i++) {
        QRadioButton *radioBtn = new QRadioButton(this);
        radioBtn->setFocusPolicy(Qt::NoFocus);
        radioBtn->setText(QString(tr("型別%1").arg(i+1)));
        radioBtn->setStyleSheet("background-color:#c2e7f9;padding-left:4px;color:#19649f;");
        radioBtn->move(40, i*30 + 70);
        group->addButton(radioBtn, i);
    }
    connect(group, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(slotButtonGroup(QAbstractButton *)));
    connect(group, SIGNAL(buttonClicked(int)), this, SLOT(slotButtonGroup(int)));
    for (int i = 0;i <7; i++){
        QLabel *label  = new QLabel(this);
        label->resize(105,3);
        label->setFrameStyle(QFrame::HLine | QFrame::Raised);
        label->setLineWidth(1);
        label->move(40, i*30 + 90);
     }

    turnPage = new PageNumberControl(this);        //control pagenumber
    turnPage->setCurrentAndTotalPage(2, 10);
    turnPage->move(40, 285);
    //connect(turnPage, SIGNAL(currentPageChanged(int)),this, SLOT(slotTurnPage(int)));

    closeBtn = new CustomBtn(this);
    closeBtn->SetImgs(":/images/dialog_btn_close_hover.png",":/images/dialog_btn_close.png","",":/images/dialog_btn_close_hover.png");
    closeBtn->setGeometry(width() - 38, 5, 32, 32);

    closeBtn->show();
    connect(closeBtn, SIGNAL(clicked()), this, SLOT(close()));
    move((QApplication::desktop()->width() - width())/2,  (QApplication::desktop()->height() - height())/2);
}

void SelectTemplate::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.drawPixmap(0, 0, backGroundPix.width(), backGroundPix.height(), backGroundPix);

    painter.setPen(QPen(QColor("#2676A1"), 2));
    painter.setFont(QFont("", 14, QFont::Black));
    painter.drawText(QRect(190, 35, 400, 40), QString(tr("選擇模板")));

    painter.setPen(Qt::NoPen);
    painter.setBrush(QColor("#c2e7f9"));
    painter.drawRect(35,60,115,250);

    painter.setPen(QPen(QColor("#d4d4d4"), 1));
    painter.drawLine(0, height() - 1, width(), height() -1);

    QDialog::paintEvent(event);
}

void SelectTemplate::slotButtonGroup(QAbstractButton * button)
{
    qDebug("-----------QAbstractButton---------------");
    qDebug() << button->text();
    qDebug() << group->checkedId();
    qDebug() << group->checkedButton();
    if (group->checkedButton()) {
        qDebug() << group->checkedButton()->text();
    }
}
void SelectTemplate::slotButtonGroup(int id)
{
    qDebug("-----------int---------------");
    qDebug() << id;
    qDebug() << group->button(id)->text();
    qDebug() << group->checkedId();
    qDebug() << group->checkedButton();
    if (group->checkedButton()) {
       qDebug() << group->checkedButton()->text();
    }
}

void SelectTemplate::slotConfirmBtn()
{
    qDebug() << "---------------final----------------";
    qDebug() << group->checkedId();
    qDebug() << group->checkedButton();
    qDebug() << group->checkedButton()->text();
    close();
}

/****************move everywhere*******************/
void SelectTemplate::mousePressEvent ( QMouseEvent * event)
{
    bPressFlag = true;
    dragPosition = event->pos();
    QDialog::mousePressEvent(event);
}

void SelectTemplate::mouseMoveEvent(QMouseEvent *event)
{
    if (bPressFlag) {
        QPoint relaPos(QCursor::pos() - dragPosition);
        move(relaPos);
    }
    QDialog::mouseMoveEvent(event);
}

void SelectTemplate::mouseReleaseEvent(QMouseEvent *event)
{
    bPressFlag = false;
    QDialog::mouseReleaseEvent(event);
}
(5)applicationinfo.h
#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include "custombtn.h"
#include "vmcontrol.h"
#include <QtGui>

class ApplicationInfo : public QWidget
{
    Q_OBJECT

public:
    ApplicationInfo(QWidget *parent = 0);
    ~ApplicationInfo();
private:
    CustomBtn *_closeBtn;
    VmmComboBox *opSystemType;
    VmmComboBox *confTemplate;
    VmmComboBox *dataDisk;
    VmmComboBox *chooseTemplate;

    QLabel *titleLabel;
    QLabel *opSystemTypeLabel;
    QLabel *confTemplateLabel;
    QLabel *dataDiskLabel;
    QLabel *chooseTemplateLabel;
    QLabel *btnLabel;

    CustomBtn *submitApplyBtn;
    CustomBtn *templateBtn;

    QMenu *_menu;
    QMenu *_disk;

protected:
    void mousePressEvent(QMouseEvent * event);
    void mouseMoveEvent(QMouseEvent * event);
    void mouseReleaseEvent(QMouseEvent *event);
    void paintEvent(QPaintEvent * event);

private:
     QPoint dragPosition;
     bool bPressFlag;

private slots:
     void slotSubmit();
     void slotChooseTemplate();
     void slotSysNav();
     void applyDisk(QAction *action);
};

#endif // DIALOG_H
(6)applicationinfo.cpp
#include "applicationinfo.h"
#include "selecttemplate.h"

ApplicationInfo::ApplicationInfo(QWidget *parent)
    : QWidget(parent)
    ,bPressFlag(false)
{
    opSystemType = new VmmComboBox(this,  QString(tr("operating system")));
    opSystemType->resizeWidth(232);
    opSystemType->move(180,75);
    opSystemType->insertItem(0, tr("General"));
    opSystemType->insertItem(1, tr("Linux older)"));
    opSystemType->insertItem(2, tr("Linux newer"));
    opSystemType->insertItem(3, "Windows XP");
    opSystemType->setCurrentIndex(3);

    confTemplate = new VmmComboBox(this,  QString(tr("configure template")));
    confTemplate->resizeWidth(232);
    confTemplate->move(180, 125);
    confTemplate->insertItem(0, tr("1Cpus 10GBMemory"));
    confTemplate->insertItem(1, tr("2Cpus 20GBMemory"));
    confTemplate->insertItem(2, tr("3Cpus 30GBMemory"));
    confTemplate->setCurrentIndex(0);

    dataDisk = new VmmComboBox(this,  QString(tr("Select a data disk")));
    dataDisk->resizeWidth(232);
    dataDisk->move(180, 175);
    dataDisk->insertItem(0, tr("10GB"));
    dataDisk->insertItem(0, tr("20GB"));
    dataDisk->setCurrentIndex(0);

    chooseTemplate = new VmmComboBox(this,  QString(tr("Select a template")));
    chooseTemplate->resizeWidth(232);
    chooseTemplate->move(180, 225);
    chooseTemplate->insertItem(0, tr("Default"));
    chooseTemplate->setCurrentIndex(0);

    btnLabel = new QLabel(this);
    btnLabel->setStyleSheet("background:rgba(255,255,255,255);");

    templateBtn = new CustomBtn(this);
    templateBtn->SetImgs(":/images/temple_btn_hover.png",
                          ":/images/temple_btn.png","",
                          ":/images/temple_btn_hover.png");
    connect(templateBtn, SIGNAL(clicked()), this, SLOT(slotChooseTemplate()));
    btnLabel->move(378,227);
    btnLabel->resize(22,30);

    templateBtn->move(378,226);
    templateBtn->resize(32,33);

    submitApplyBtn = new CustomBtn(this);
    submitApplyBtn->SetImgs(":/images/dialogBtn_hover.png", ":/images/dialogBtn.png"
                     , "", ":/images/dialogBtn.png");
    submitApplyBtn->move(185, 275);
    submitApplyBtn->setText(QString(tr("提交")));
    connect(submitApplyBtn, SIGNAL(clicked()), this, SLOT(slotSubmit()));

    setAutoFillBackground(true);
    setWindowFlags(Qt::FramelessWindowHint); // | Qt::WindowStaysOnTopHint);
    QPalette p;
    p.setBrush(QPalette::Window, QBrush(QColor("#EDF5F9")));    //color
    this->setPalette(p);
    //setWindowState(Qt::WindowFullScreen);
    resize(450, 350);

    CustomBtn *_sysNav = new CustomBtn(this);
    _sysNav->SetHoverImg(":/images/window_sysNav_hover.png");
    _sysNav->SetNormalImg(":/images/window_sysNav.png");
    _sysNav->move(0, 0);
    connect(_sysNav, SIGNAL(clicked()), this, SLOT(slotSysNav()));

    setStyleSheet("QMenu::item {background-color: #ebf6fd;padding: 3px 10px 3px 20px;border: 0px solid transparent;color: #19649f"
                  "}QMenu::item:selected  {background-color: #006699;color: white} QMenu::item:!enabled{color: gray}");
    _menu = new QMenu(this);
    _disk = new QMenu(tr("Apply Disk   "), _menu);
    _menu->addMenu(_disk);
    for (int i = 1; i < 10; i++) {
        _disk->addAction(QString("%1GB").arg(10 * i));
    }
    connect(_disk , SIGNAL(triggered(QAction*)), this, SLOT(applyDisk(QAction*)));

    QAction *account = _menu->addAction(tr("Account"));
    QAction *about = _menu->addAction(tr("about"));
    QAction *exit = _menu->addAction(tr("exit"));
    connect(exit, SIGNAL(triggered()), this, SLOT(close()));

    _closeBtn = new CustomBtn(this);
    _closeBtn->SetImgs(":/images/dialog_btn_close_hover.png",":/images/dialog_btn_close.png","",":/images/dialog_btn_close_hover.png");
    _closeBtn->setGeometry(width() - 32, 0, 32, 32);
    _closeBtn->show();
    connect(_closeBtn, SIGNAL(clicked()), this, SLOT(close()));
    move((QApplication::desktop()->width() - width())/2,  (QApplication::desktop()->height() - height())/2);
}

ApplicationInfo::~ApplicationInfo()
{

}

void ApplicationInfo::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);

    painter.setPen(QPen(QColor("#333333")));
    painter.setFont(QFont("", 11, QFont::Normal));
    painter.drawText(QRect(50, opSystemType->pos().y() + 10, 200, 20), QString(tr("system:")));
    painter.drawText(QRect(50, confTemplate->pos().y() + 10, 200, 20), QString(tr("template :")));
    painter.drawText(QRect(50, dataDisk->pos().y() + 10, 200, 20), QString(tr("datadisk:")));
    painter.drawText(QRect(50, chooseTemplate->pos().y() + 10, 200, 20), QString(tr("template:")));

    painter.setPen(QPen(QColor("#2676A1"), 2));
    painter.setFont(QFont("", 16, QFont::Black));
    painter.drawText(QRect(200, 25, 400, 40), QString(tr("資訊顯示")));
    QWidget::paintEvent(event);
}

void ApplicationInfo::slotSubmit()
{
    QMessageBox::information(this,tr("info"),tr("ok!"));
}

void ApplicationInfo::slotChooseTemplate()
{
    SelectTemplate *templateInfo = new SelectTemplate;
    templateInfo->move(this->pos());
    templateInfo->setModal(true);
    templateInfo->show();
}

void ApplicationInfo::slotSysNav()
{
    //_menu->popup(this->mapToGlobal( QPoint(_sysNav->geometry().left() - 140, 20)));
    _menu->popup(mapToGlobal(QPoint(15, 0)));
}

void ApplicationInfo::applyDisk(QAction * action)
{
    qDebug() << action->text();
}

void ApplicationInfo::mousePressEvent ( QMouseEvent * event)
{
    bPressFlag = true;
    dragPosition = event->pos();
    QWidget::mousePressEvent(event);
}

void ApplicationInfo::mouseMoveEvent(QMouseEvent *event)
{
    if (bPressFlag) {
        QPoint relaPos(QCursor::pos() - dragPosition);
        move(relaPos);
    }
    QWidget::mouseMoveEvent(event);
}

void ApplicationInfo::mouseReleaseEvent(QMouseEvent *event)
{
    bPressFlag = false;
    QWidget::mouseReleaseEvent(event);
}

(7)waitingwidget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QtGui>

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = 0);
    ~Widget();

    void start();
    void stop();
    void setMaskWidget(bool flag);
private slots:
    void slotRotatePic(qreal value);

private:
    QTimeLine *timeline;
    int picture_number;
    int counter;
    QWidget *maskWidget;
    QLabel *waitingLabel;
};

#endif // WIDGET_H

(8)waitingwidget.cpp

#include "waitingwidget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , picture_number(12)
    , counter(0)
{
    setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    setAutoFillBackground(true);

    QPalette pal = palette();
    pal.setColor(QPalette::Background, QColor(0xFF,0xFF,0xFF,0x00));
    setPalette(pal);

    setVisible(false);
    //resize(42, 42);
    timeline=new QTimeLine(picture_number*1000,this);
    timeline->setFrameRange(1,picture_number);
    timeline->setUpdateInterval(50);
    timeline->setLoopCount(0);

    waitingLabel = new QLabel(this);
    waitingLabel->resize(42, 42);

    maskWidget = new QWidget(this, Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
    maskWidget->setStyleSheet( "background-color:rgba(0, 0, 0,35)");
    maskWidget->hide();

    if (parent) {
        maskWidget->resize(parent->size());
        waitingLabel->move((parent->width() - waitingLabel->width())/2,  (parent->height() - waitingLabel->height())/2);
        this->move(parent->pos());
    }

    connect(timeline,SIGNAL(valueChanged(qreal)),this,SLOT(slotRotatePic(qreal)));

}

Widget::~Widget()
{

}

void Widget::start()
{
    timeline->start();
    timeline->setLoopCount(0);
    this->setVisible(true);
}

void Widget::stop()
{
    timeline->stop();
    this->setVisible(false);
}

void Widget::slotRotatePic(qreal value)
{
    if(counter > 11)  counter = 0;
    QPixmap backGroundPix(QString(":/images/loading_%1.png").arg(counter+1));
    backGroundPix = backGroundPix.scaled(QSize(42, 42), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    waitingLabel->setPixmap(backGroundPix);

    update();
    counter++;
}
void Widget::setMaskWidget(bool flag)
{
    if (flag == true)  maskWidget->show();
    else  maskWidget->hide();
}

2、執行


三、總結

(1)上述程式碼僅提供思路參考,只有介面的顯示,也還有一些功能bug。
(2)若需要相應的介面效果可以發郵件聯絡,[email protected]
(3)若有問題或建議,請留言,在此感謝!

相關推薦

Qt介面定義

一、簡介       Qt自帶的介面不利於樣式的調整和美化,自定義介面便於設計風格。 二、詳解 1、程式碼 (1)pagenumbercontrol.h #ifndef PAGENUMBERCONTROL_H #define PAGENUMBERCONTROL_H

Qt一QT_OpenGL

一、簡介           最近想了解些Qt的OpenGL程式設計,可能以後會使用。Opengl是對2D和3D圖形支援很好,有非常多的優化函式,而且是個跨平臺的開源庫。Qt的Opengl封裝的很好,通過Qt的QGLWidget類,將opengl的函式和Qt的介面結合了

Qt2048遊戲(原始程式碼來自網路)

一、簡介         Qt改寫2048遊戲,在linux系統下找尋android的視覺效果。 二、執行圖         啟動執行圖: 三、詳解 1、程式碼 (1)widget.h #ifndef WIDGET_H #define WIDGET_H #inclu

Qt一log調試日誌

gms 生成文件 _file__ ica 沒有 rest delet mar 排除 一、簡單介紹 近期因調試code時,想了解程序的流程,但苦於沒有一個簡易的日誌記錄,不停使用qDebug打印輸出,而終於提交代碼時得去多次刪除信息打印,有時還會出現新改動

Qt八視窗下方彈出提示資訊

一、簡介       在專案中一般都會彈出新的子對話方塊顯示提示資訊,但對於一些因後臺資料變化引發的提示還是在視窗下方彈出提示資訊比較合理。點選按鈕彈出提示資訊,當滑鼠放在提示資訊對話方塊上時,暫停動畫可長時間檢視提示資訊。 二、詳解 1、程式碼 (1)fader

Qt二二維碼條形碼解析

一、簡介         二維條碼/二維碼(2-dimensional bar code)是用某種特定的幾何圖形按一定規律在平面(二維方向上)分佈的黑白相間的圖形記錄資料符號資訊的,其應用廣泛,如:產品防偽/溯源、廣告推送、網站連結、資料下載、商品交易、定位/導航、電子憑

Qt一QLineEdit的新樣式和補全歷史記錄

一、簡介        利用背景圖片設計出QLineEdit新的樣式,起到美化介面的效果,並增加自動補全歷史記錄的功能,就可以作為一個完整的庫。  二、詳解 1、知識點 (1)切換QLineEdit的背景 void InnerLineEdit::setNormal()

Qt一log除錯日誌

一、簡介       最近因除錯code時,想了解程式的流程,但苦於沒有一個簡易的日誌記錄,不停使用qDebug列印輸出,而最終提交程式碼時得去多次刪除列印資訊,有時還會出現新修改的程式碼分不清是哪些部分。而使用#ifdef _DEBUG又比較煩這套,因此寫了些簡單的日誌

Qt八解析XML檔案

一、簡介         QtXml模組提供了一個讀寫XML檔案的流,解析方法包含DOM和SAX。DOM(Document ObjectModel):將XML檔案表示成一棵樹,便於隨機訪問其中的節點,但消耗記憶體相對多一些。SAX(Simple APIfor XML):一

QtQt樣式表

一、簡介       不斷總結好的樣式表,美化自己的介面(在實際工作中會不斷的更新)。 二、詳解 1、載入樣式表文件 QFile file(":/qss/stylesheet.qss"); file.open(QFile::ReadOnly); QString sty

QtCentos下Qt結合v4l2實現的視訊顯示

一、簡介        v4l2是針對uvc免驅usb裝置的程式設計框架,主要用於採集usb攝像頭。 可從網上下載最新的原始碼(包括v4l2.c和v4l2.h兩個檔案),本文中修改過。       Qt執行介面如下(動態變化的): 二、詳解 1、準備 (1)插入usb攝

Qt二:拖拽文字圖片

一、簡介        首先選擇窗體顯示風格,接著顯現拖拽效果,文字和圖示都可以作為拖拽的物件,在窗體中的文字圖示可以拖拽到視窗的任意位置,它們在兩個獨立執行的程式間也可相互拖拽(此時是複製一份到拖拽目的程式視窗中),文字拖拽的範圍更廣(須注意字符集的轉換)。本文解決這種

Qt六:TCP和UDP(之一)

一、簡介        Qt使用QtNetwork模組來進行網路程式設計,提供了一層統一的套接字抽象用於編寫不同層次的網路程式,避免了應用套接字進行網路編的繁瑣(因有時需引用底層作業系統的相關資料結構)。有較底層次的類如QTcpSocket、QTcpServer和QUdp

Python例項Python守護程序和指令碼單例執行

一、簡介      守護程序最重要的特性是後臺執行;它必須與其執行前的環境隔離開來,這些環境包括未關閉的檔案描述符、控制終端、會話和程序組、工作目錄以及檔案建立掩碼等;它可以在系統啟動時從啟動指令碼/etc/rc.d中啟動,可以由inetd守護程序啟動,也可以有作業規劃程

Android Studio 第一期 - 定義RecycleView Gallery

recycleview gallery 代碼已經整理好,效果如下圖:(支持Verical Horizontal 支持自定義放大位置 支持滾動速度) 圖片1: 圖片2: 地址:https://github.com/geeklx/MyApplication/tree/

Android Studio 第三期 - 定義EditText密碼鍵盤

android edittext 代碼已經整理好,效果如下圖: code: //設置輸入為密碼模式 inputETP1.setInputType(InputType.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATIO

Android Studio 第二期 - 定義WheelPicker

android wheelpicker 代碼已經整理好,效果如下圖: 地址:https://github.com/geeklx/MyApplication/tree/master/p038_wheelpicker本文出自 “梁肖技術中心” 博客,請務必保留此出處http://liangxi

碼農裝13寶典系列:Ubuntu定義字型縮放級別

目前主流顯示器都有一個很高的解析度,而使用預設的解析度會使字型顯示過小,單純地調整解析度又容易讓字看起來發虛。 系統提供了一個字型縮放級別調整的功能。Windows初始化時就已經為使用者設定好了,而Ubuntu只有兩個選項:100%、200%,顯然不能滿足需求。 那怎麼辦? 這裡需要

Python介面(3):Python例項三Python與C/C++相互呼叫

一、問題      Python模組和C/C++的動態庫間相互呼叫在實際的應用中會有所涉及,在此作一總結。 二、Python呼叫C/C++ 1、Python呼叫C動態連結庫         Python呼叫C庫比較簡單,不經過任何封裝打

shell一別名、列表及陣列

一、簡介 Shell中別名可以對命令進行重新命名,方便使用者記憶長命名和定製自己熟悉的工作環境;列表是一組命名以邏輯與、邏輯或的關係串在一起,實現指令碼程式的邏輯控制;陣列是一重點,涉及陣列的賦值、操作和字串的處理,以及利用陣列實現堆疊和二維陣列等資料結構的儲存。 二、