Setting the background-color of separators only works when separators are draggable



  • I have three QDockWidgets on my QMainWindow. I would like to change the color of the separators. I'd also like to make the separators 2 pixels thick so I tried setting the stylesheet of the window to this:

    QMainWindow::separator {
      width: 2px;
      height: 2px;
      background-color: #B8CDD7;
    }
    

    The dock on the bottom of the screen is resizable and the separator has the color correctly applied. The docks on the left and right are not resizable and the separator doesn't have the color applied. The width of the side docks is being set but the background color is the default window background. Maybe the separators are invisible when they aren't draggable? Or perhaps I need to use a selector for non-draggable separators?

    As a quick test, I removed a call to setFixedWidth from one of the side docks and the separator color was correctly applied. This definitely has something to do with the draggability of the separators.


  • Lifetime Qt Champion

    Hi,

    You should also mention:

    • Qt version
    • OS running

    Can you provide a minimal compilable example that shows your situation ?



  • @SGaist Here's an MCVE of the problem:

    #include <QtWidgets/qdockwidget.h>
    #include <QtWidgets/qmainwindow.h>
    #include <QtWidgets/qapplication.h>
    
    void addDock(QMainWindow *window, Qt::DockWidgetArea area, QWidget *widget) {
      QDockWidget *dock = new QDockWidget{window};
      dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
      dock->setAllowedAreas(area);
      dock->setWidget(widget);
      dock->setTitleBarWidget(new QWidget{dock});
      window->addDockWidget(area, dock);
    }
    
    int main(int argc, char **argv) {
      QApplication app{argc, argv};
      QMainWindow window;
      
      window.setStyleSheet(R"(
        QMainWindow::separator {
          width: 10px;
          height: 10px;
          background-color: #F00;
        }
      )");
      
      QWidget bottom{&window};
      bottom.setMinimumHeight(100);
      bottom.setStyleSheet("background-color: #0F0");
      addDock(&window, Qt::BottomDockWidgetArea, &bottom);
      
      QWidget left{&window};
      left.setFixedWidth(100);
      left.setStyleSheet("background-color: #00F");
      addDock(&window, Qt::LeftDockWidgetArea, &left);
      
      QWidget center{&window};
      center.setMinimumSize(300, 300);
      center.setStyleSheet("background-color: #0FF");
      window.setCentralWidget(&center);
      
      window.show();
      
      return app.exec();
    }
    

    This is what I'm seeing:

    Screenshot

    Notice that the separator between the left widget and the central widget is the default window background color (not red).

    I'm using Qt 5.12.3 on macOS 10.14.4



  • Could this be a bug? Maybe I'm just doing something wrong?


  • Lifetime Qt Champion

    I think you have found a bug. Did you already check the bug report system ? If not, please do so and if you find nothing, consider opening a new report providing your example. If there's already a report, update it with the information you currently have.

    I can also confirm this happens on Linux with the current dev branch of qtbase.



  • @SGaist I had a look at the bug tracker and couldn't anything. I'll open a new bug report and post a link here.




Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.