QWidget Semi-transparent Background Color/bg
Български English
Полупрозрачен цвят на фона на QWidget
Този отрязйк от програмен код показва как са се постигне прозрачност на цвета на фона на "QWidget":http://doc.qt.io/qt-5.0/qtwidgets/qwidget.html чрез предефиниране на "paintEvent()":http://doc.qt.io/qt-5.0/qtwidgets/qwidget.html#paintEvent.
- Предефиниране на paintEvent
.h файл
protected:
//overload from QWidget
void paintEvent(QPaintEvent* event);
- Имплементиране на paintEvent
.cpp файл
void MyWidget::paintEvent(QPaintEvent* /*event*/)
{
QColor backgroundColor = palette().light().color();
backgroundColor.setAlpha(200);
QPainter customPainter(this);
customPainter.fillRect(rect(),backgroundColor);
}
Този отрязък от код е вдъхновен от предложеното решение от Antonio Di Monaco в "тази тема във форума":http://developer.qt.nokia.com/forums/viewthread/1488.
Вижте също
"Как се сменя цвета на фона на QWidget":http://developer.qt.nokia.com/wiki/How_to_Change_the_Background_Color_of_QWidget_Bulgarian