Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.3.1
-
None
-
Windows7 32bit
Description
I noticed a painting problem, if there is a combination of following 3 parts:
- Qt::FramelessWindowHint
- setContentsMargins(0, 0, 0, 0)
- Qt::AA_NativeWindows
The example below illustrates the problem
Start the example and click on the "up" or "down" button, the label should show an increased or decreased value.
But it doesn't, even the "pressed" state of the button is not painted. The mouse click event comes, it seems that only painting events have problems
But if you comment out the part with Qt::FramelessWindowHint or Qt::AA_NativeWindows painting is fine.
The same if you change the line verticalLayout->setContentsMargins(0, 0, 0, 0) to lets say verticalLayout->setContentsMargins(1, 0, 0, 0)
It is just the combination of the three parts which causes the problem.
I encountered this problem when I was porting a Qt4 project to Qt5, in Qt4 painting is fine.
It took me quite a while to reduce the problem to simple example and I could not believe how layouting could influence this
#include <QApplication> #include <QtWidgets/QGridLayout> #include <QtWidgets/QLabel> #include <QtWidgets/QPushButton> #include <QtWidgets/QVBoxLayout> #include <QtWidgets/QWidget> class FrameLessWidget : public QWidget { public: FrameLessWidget(QWidget* parent = 0) : QWidget(parent) , value(0) { // Part 1 setWindowFlags(windowFlags() | Qt::FramelessWindowHint); setupUi(this); downButton->setText("Down"); upButton->setText("Up"); label->setText("---"); exitButton->setText("Exit"); connect(upButton, &QPushButton::clicked, this, &FrameLessWidget::increase); connect(downButton, &QPushButton::clicked, this, &FrameLessWidget::decrease); connect(exitButton, &QPushButton::clicked, []() { qApp->exit(); }); } void setupUi(QWidget* parent) { parent->resize(400, 300); QVBoxLayout* verticalLayout = new QVBoxLayout(parent); // Part 2 verticalLayout->setContentsMargins(0, 0, 0, 0); // Don't work! no PaintEvents? //verticalLayout->setContentsMargins(1, 0, 0, 0); // works! QWidget* widget = new QWidget(parent); QGridLayout* gridLayout = new QGridLayout(widget); downButton = new QPushButton(widget); gridLayout->addWidget(downButton, 1, 1, 1, 1); label = new QLabel(widget); gridLayout->addWidget(label, 0, 0, 1, 1); upButton = new QPushButton(widget); gridLayout->addWidget(upButton, 0, 1, 1, 1); exitButton = new QPushButton(widget); gridLayout->addWidget(exitButton, 2, 1, 1, 1); verticalLayout->addWidget(widget); } void decrease() { value++; label->setText(QString::number(value)); } void increase() { value--; label->setText(QString::number(value)); } private: QPushButton* downButton; QPushButton* upButton; QLabel* label; QPushButton* exitButton; int value; }; int main(int argc, char* argv[]) { QApplication a(argc, argv); // Part 3 a.setAttribute(Qt::AA_NativeWindows); FrameLessWidget w; w.show(); return a.exec(); }
Attachments
Issue Links
- is replaced by
-
QTBUG-39220 Windows: Rendering issues in fullscreen when QGLWidget/native widget used inside QTabWidget and QMainWindow
- Closed