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

Widget inheriting from QWidget not rendering when using setFixedSize and setStyleSheet

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.0
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Qt 5.15.0, CMake 3.17, Qt Creator 4.12.3
    • Platform/s:
      Linux/X11

      Description

      I was working on an application based on 3 panels (status bar, side bar, content) and I found out that when I create a custom widget that inherits from QWidget and uses setFixedSize() and setStyleSheet() nothing is rendered.

      Everything is fine and it renders a 1280x60 rectangle (see attached screenshot 1) using a QWidget directly:

      QWidget * bar1 = new QWidget(this);
      bar1->setFixedSize(1280, 60);
      bar1->setStyleSheet(QString("background: #333333;"));

      Whereas this renders nothing (see attached screenshot 2):

      StatusBar * bar1 = new StatusBar(this);
      bar1->setFixedSize(1280, 60);
      bar1->setStyleSheet(QString("background: #333333;"));

       

      And StatusBar simply inherits from QWidget without adding any code:

      #include <QWidget>

      class StatusBar : public QWidget
      {
          Q_OBJECT

      public:
          explicit StatusBar(QWidget * parent = nullptr);
      };

      I would expect to get exactly the same result, but apparently something is not working when inheriting from a QWidget.

       

      A workaround is to re-implement the paintEvent() function, but this is still unexpected and wrong behavior.

       

      I have attached an example project for reference.

        Attachments

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

          Activity

            People

            Assignee:
            qt.team.quick.subscriptions Qt Quick and Widgets Team
            Reporter:
            vivaladav Davide Coppola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes