QWidget Semi-transparent Background Color: Difference between revisions
Jump to navigation
Jump to search
AutoSpider (talk | contribs) (Add "cleanup" tag) |
AutoSpider (talk | contribs) (Convert ExpressionEngine links) |
||
Line 8: | Line 8: | ||
= QWidget Semi-transparent Background Color = | = QWidget Semi-transparent Background Color = | ||
This code snippet shows how to make the background color of | This code snippet shows how to make the background color of [http://doc.qt.io/qt-5.0/qtwidgets/qwidget.html QWidget] semi-transparent by overloading [http://doc.qt.io/qt-5.0/qtwidgets/qwidget.html#paintEvent paintEvent()]. | ||
* Declare overload of paintEvent | * Declare overload of paintEvent | ||
Line 33: | Line 33: | ||
</code> | </code> | ||
The code snippet is inspired by solution proposed by '''Antonio Di Monaco''' at | The code snippet is inspired by solution proposed by '''Antonio Di Monaco''' at [http://developer.qt.nokia.com/forums/viewthread/1488 this forum thread]. | ||
== See Also == | == See Also == | ||
[http://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget How to Change the Background Color of QWidget] |
Revision as of 15:15, 4 March 2015
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine. Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean. |
English Български
QWidget Semi-transparent Background Color
This code snippet shows how to make the background color of QWidget semi-transparent by overloading paintEvent().
- Declare overload of paintEvent
.h file
protected:
//overload from QWidget
void paintEvent(QPaintEvent* event);
- Implement the overload of paintEvent
.cpp file
void MyWidget::paintEvent(QPaintEvent* /*event*/)
{
QColor backgroundColor = palette().light().color();
backgroundColor.setAlpha(200);
QPainter customPainter(this);
customPainter.fillRect(rect(),backgroundColor);
}
The code snippet is inspired by solution proposed by Antonio Di Monaco at this forum thread.