StupidBeauty
Read times:1353Posted at:Sat Dec 10 23:30:13 2011
- no title specified

转载:QtWidget 实现不规则窗体与按钮

实现不规则按钮时,可使用QWidget::setMask(const QRegion &)函数。

http://mobile.51cto.com/symbian-270171.htm

亮点:

QWidget有很多成员函数,但是它们中的一些有少量的直接功能:例如,QWidget有一个字体属性,但是它自己从来不用。有很多继承它的子类提供了实际的功能,比如QPushButton、QListBox和QTabDialog等等。

关键是使用

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

只有widget与region重叠的地方才会显示出来. 自己构造一个QRegion就行了.

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

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands