Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-40592

Painting problem for combination of Qt::FramelessWindowHint, Qt::AA_NativeWindows and setContentsMargins(0, 0, 0, 0)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.3.1
    • GUI: Painting
    • 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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Unassigned Unassigned
              work7 Siebenhandl
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes