自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

QtWidget 實現(xiàn)不規(guī)則窗體與按鈕

移動開發(fā)
本文接受的是QtWidget 實現(xiàn)不規(guī)則窗體與按鈕,QWidget類是所有用戶界面對象的基類,一個小小的實現(xiàn)效果技巧與大家分享。

QWidget有很多成員函數(shù),但是它們中的一些有少量的直接功能:例如,QWidget有一個字體屬性,但是它自己從來不用。有很多繼承它的子類提供了實際的功能,比如QPushButton、QListBox和QTabDialog等等。

關(guān)鍵是使用

  1. void QWidget::setMask ( const QBitmap & bitmap )  
  2. void QWidget::setMask ( const QRegion & region )  
  3. void QWidget::setMask ( const QRegion & region )  
  4. Causes only the parts of the widget which overlap region to be visible.  

只有widget與region重疊的地方才會顯示出來. 自己構(gòu)造一個QRegion就行了.

  1. void ShapedClock::resizeEvent(QResizeEvent * /* event */) {  
  2.     int side = qMin(width(), height());  
  3.     QRegion maskedRegion(width() / 2 - side / 2, height() / 2 - side / 2, side,  
  4.                          side, QRegion::Ellipse);  
  5.     setMask(maskedRegion);  

void QWidget::setMask ( const QBitmap & bitmap )

Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. If the region includes pixels outside the rect() of the widget, window system controls in that area may or may not be visible, depending on the platform.

只有在bitmap中像素數(shù)據(jù)是1的地方才會顯示出widget的相應(yīng)像素來. Bitmap就是像素數(shù)據(jù)只有兩個值: 0和1 (1 bit-depth, monochrome).

 

  1. QLabel topLevelLabel;  
  2. QPixmap pixmap(":/images/tux.png");  
  3. topLevelLabel.setPixmap(pixmap); 

     topLevelLabel.setMask(pixmap.mask()); // 可以不使用轉(zhuǎn)換的, 使用一張專門的bitmap圖片.上面的這些方式用一普通的QWidget就可以了. 當(dāng)然, 對于窗口而言, 很多時候我們要把它的標(biāo)題欄去掉:widget->setWindowFlags(Qt::FramelessWindowHint);但是對于不規(guī)則的QPushButton就有些特殊, 要使用QIcon來處理:

  1. button->setIcon(QIcon("xxx.png"));
  2. button->setIconSize(w, h);
  3. button->setMask(maskBitmap/*maskedRegion*/);
  4. button->setFixedSize(w, h);   // 這個當(dāng)然最好使用它的icon的大小. 

小結(jié):QtWidget 實現(xiàn)不規(guī)則窗體與按鈕的內(nèi)容介紹完了,編程的友人們總是喜歡做些比較炫的效果,QtWidget幫了我們的大忙!最后希望本文對你有幫助。

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2015-07-17 13:31:20

按鈕單獨控制

2010-08-31 09:46:23

C#

2009-12-25 10:20:28

WPF窗口

2010-09-08 17:20:42

CSS

2009-07-10 11:31:45

Swing支持透明和不規(guī)則窗口

2010-01-11 15:31:04

VB.NET拖動窗體

2015-02-02 16:21:26

android瀑布流圖片加載

2010-09-14 10:34:17

DIV CSS

2020-11-10 15:22:46

算法PythonIoU

2022-12-22 08:34:22

CSS不規(guī)則圖形

2021-03-30 07:47:46

SVG 濾鏡 CSS技巧

2009-09-07 04:59:12

C#模式窗體

2011-06-15 09:24:36

Qt Widget Model

2009-09-07 06:56:46

C#透明窗體

2022-12-28 07:48:40

六邊形動畫CSS

2024-01-03 08:30:54

Redis分布式項目

2011-06-20 17:17:11

Qt Widget QWidget

2011-06-20 16:54:40

Qt Widget model

2011-02-16 14:15:58

FringAndroid應(yīng)用iOS應(yīng)用

2009-09-01 18:06:06

c#保存窗體狀態(tài)
點贊
收藏

51CTO技術(shù)棧公眾號