<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > QT實現(xiàn)不規(guī)則窗體

          QT實現(xiàn)不規(guī)則窗體

          作者: 時間:2016-10-08 來源:網(wǎng)絡(luò) 收藏

          看到網(wǎng)上有很多的實現(xiàn),效果很酷.于是使用也實現(xiàn)了一個,實現(xiàn)非常簡單,只需要設(shè)置一個mask(遮掩)圖片,這個圖片的格式可以使用png或bmp格式,我使用了png格式,默認窗體是矩形的,使用png圖像,將需要隔離在窗體之外的區(qū)域的像素設(shè)置為白色或透明色,其他顏色的區(qū)域?qū)?yīng)顯示出來的窗體.關(guān)鍵代碼就幾行.

          本文引用地址:http://www.ex-cimer.com/article/201610/305993.htm

          #ifndef IRREGULARFORM_H

          #define IRREGULARFORM_H

          #include

          #include ui_irregularform.h

          #include

          #include

          #include

          #include

          class IrregularForm : public QWidget

          {

          Q_OBJECT

          public:

          IrregularForm(QWidget *parent = 0);

          ~IrregularForm();

          protected:

          void mouseMoveEvent(QMouseEvent *event);

          void mousePressEvent(QMouseEvent *event);

          void mouseReleaseEvent(QMouseEvent *event);

          private:

          Ui::IrregularFormClass ui;

          QPoint mouseMovePos;

          };

          #endif // IRREGULARFORM_H

          #include irregularform.h

          IrregularForm::IrregularForm(QWidget *parent)

          : QWidget(parent)

          {

          setWindowFlags(Qt::FramelessWindowHint);

          QPixmap mask(:/IrregularForm/Resources/mask.png);//加載掩碼圖像

          setMask(QBitmap(mask.mask())); //設(shè)置窗體的掩碼圖像,摳除圖像的白色區(qū)域?qū)崿F(xiàn)

          QPalette p;//設(shè)置調(diào)色板

          p.setBrush(QPalette::Window, QBrush(mask));//將調(diào)色板的畫刷設(shè)置為掩碼位圖,在不規(guī)則窗體上顯示出掩碼位圖

          setPalette(p);

          mouseMovePos = QPoint(0, 0);

          }

          IrregularForm::~IrregularForm()

          {

          }

          void IrregularForm::mouseMoveEvent(QMouseEvent *event)//鼠標按下并移動則移動不規(guī)則窗體

          {

          if(mouseMovePos != QPoint(0, 0))

          {

          move(geometry().x() + event->globalPos().x() - mouseMovePos.x(), geometry().y() + event->globalPos().y() - mouseMovePos.y());

          mouseMovePos = event->globalPos();

          }

          }

          void IrregularForm::mousePressEvent(QMouseEvent *event)

          {

          mouseMovePos = event->globalPos();

          }

          void IrregularForm::mouseReleaseEvent(QMouseEvent *event)

          {

          mouseMovePos = QPoint(0, 0);

          }

          效果圖



          關(guān)鍵詞: QT 不規(guī)則窗體

          評論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();