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

Stylesheet not applied to a docked QDockWidget

    XMLWordPrintable

Details

    Description

      It should be possible to set a stylesheet on a QDockWidget where it will be applied both when docked and floating, however it seems that currently when setting a stylesheet on a QDockWidget that it will only be applied when that QDockWidget is floating. Either the styling of this widget should be consistent or the correct way for styling a docked QDockWidget should be documented.

      The following example demonstrates this issue:

      #include <QtGui>
      #include <QApplication>
      class DockContent : public QWidget
      {
          public:
              DockContent ()
              {
                  QLabel* l1 =  new QLabel ("Item Label 1");
                  QLabel* l2 =  new QLabel ("Item Label 2");
                  QLabel* l3 =  new QLabel ("Item Label 3");
                  QLabel* l4 =  new QLabel ("Item Label 4");
                  QLabel* l5 =  new QLabel ("Item Label 5");
      
                  QVBoxLayout* v1 = new QVBoxLayout();
                  v1->addWidget (l1);
                  v1->addWidget (l2);
                  v1->addWidget (l3);
                  v1->addWidget (l4);
                  v1->addWidget (l5);
                  QSpacerItem* verticalSpacer = new QSpacerItem(20, 363, QSizePolicy::Minimum, QSizePolicy::Expanding);
                  v1->addItem(verticalSpacer);
      
                  setLayout (v1);
              }
      };
      
      class DockWidget :public QDockWidget
      {
          public:
              DockWidget ()
              {
                  setObjectName ("Dock_Widget");
      
                  dockContent = new DockContent();
                  dockContent->setObjectName("dock_content");
                  setWidget(dockContent);
                  setFixedSize (160,600);
              }
          private:
              DockContent *dockContent;
      };
      
      class MainWindow : public QMainWindow
      {
          public:
               MainWindow ()
               {
                   DockWidget* d = new DockWidget ();
                   addDockWidget (Qt::LeftDockWidgetArea, d);
      
                   QTableWidget* w = new QTableWidget (600, 5);
                   setCentralWidget (w);
      
                   setFixedSize (600,600);
                   this->centralWidget()->setStyleSheet ( "QDockWidget#Dock_Widget{ border-radius:6px ; \
                                                                         border:1px solid rgba(237, 237, 237, 255); \
                                                                         background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0.856444 rgba(214, 214, 214, 255), \
                                                                             stop:0.950888 rgba(255, 255, 255, 255), stop:0.980424 rgba(217, 217, 217, 255))}");
      
               }
      
      };
      
      
      
      int main (int n, char** c)
      {
          QApplication app (n,c);
      
          MainWindow w;
          w.show ();
      
         app.setStyleSheet ( "QDockWidget{ border-radius:6px ; \
                          border:1px solid rgba(237, 237, 237, 255); \
                          background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0.856444 rgba(214, 214, 214, 255), \
                              stop:0.950888 rgba(255, 255, 255, 255), stop:0.980424 rgba(217, 217, 217, 255))}");
      
          return app.exec ();
      }
      
      

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            janichol Andy Nichols
            Votes:
            22 Vote for this issue
            Watchers:
            15 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes