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

Widget inheriting from QWidget not rendering when using setFixedSize and setStyleSheet

    XMLWordPrintable

Details

    • 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

        1. fixedsize_widgets-inherit.png
          7 kB
          Davide Coppola
        2. fixedsize_widgets-qwidget.png
          7 kB
          Davide Coppola
        3. FixedSizeWidgets.cbp
          19 kB
          Davide Coppola
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

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

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes