Styling a QDockWidget's title



  • Hi :-)

    I used to set a style sheet for my program's QDockWidgets to style the title (make it bigger) like this:

    dock->setStyleSheet(QStringLiteral("QDockWidget { font-size: 18pt; }"));
    

    which worked fine until I updated to Qt 5.11 recently. The above code has no effect anymore. I also tried the QDockWidget::title subcontrol, but all font size settings there are also ignored.

    Is this a bug or a feature?! ;-) Or: How can I style a QDockwidget's title for both Qt 5.11 and older versions?

    Thanks for all help!


  • Lifetime Qt Champion

    Hi,

    Sounds like it could be a regression.

    On what platform do you observe that ? Did you check on another ?



  • I'm on Gentoo, using Qt 5.11.1. If you think it's a bug, I could also try to update to Qt 5.11.2 (also in portage) and see what happens …


  • Lifetime Qt Champion

    No need to upgrade. It's a regression between 5.10.1 and 5.11. Can you please create a bug report?



  • Thanks for the feedback, I'll file one :-)



  • Here we are: I just filed Bug #71382.



  • @Christian-Ehrlicher Would it be possible to simply revert https://code.qt.io/cgit/qt/qtbase.git/commit/?id=3de8e74d773185b4c72b9fc730fdbb7275bed2d6 in my local Qt build to fix this for the moment? Or would this cause other trouble? I think it will take some time until a release having this fixed hits Gentoo's Portage tree …



  • I just found Bug #70276, which seems to describe this very issue and points to a Patch apparently to be introduced with Qt 5.12: https://codereview.qt-project.org/#/c/241099/2/src/widgets/widgets/qdockwidget.cpp

    So it's already fixed?!


  • Lifetime Qt Champion

    @l3u_ said in Styling a QDockWidget's title:

    So it's already fixed?!

    I would guess yes but need to take a look on it later on.



  • At least, the changes linked to the bug I found also fixes it for Qt 5.11.1. here's the patch I applied:

    --- a/src/widgets/widgets/qdockwidget.cpp 2018-10-26 13:19:34.274455524 +0200
    +++ b/src/widgets/widgets/qdockwidget.cpp 2018-10-26 13:22:18.305395057 +0200
    @@ -691,7 +691,6 @@
         // If we are in a floating tab, init from the parent because the attributes and the geometry
         // of the title bar should be taken from the floating window.
         option->initFrom(floatingTab && !isFloating() ? parentWidget() : this);
    -    option->fontMetrics = QFontMetrics(d->font);
         option->rect = dwlayout->titleArea();
         option->title = d->fixedWindowTitle;
         option->closable = hasFeature(this, QDockWidget::DockWidgetClosable);
    @@ -1468,6 +1467,7 @@
     void QDockWidget::paintEvent(QPaintEvent *event)
     {
         Q_UNUSED(event)
    +    Q_D(QDockWidget);
     
         QDockWidgetLayout *layout
             = qobject_cast<QDockWidgetLayout*>(this->layout());
    @@ -1488,7 +1488,11 @@
             // the title may wish to extend out to all sides (eg. Vista style)
             QStyleOptionDockWidget titleOpt;
             initStyleOption(&titleOpt);
    -        p.setFont(d_func()->font);
    +        if (font() == QApplication::font("QDockWidget")) {
    +            titleOpt.fontMetrics = QFontMetrics(d->font);
    +            p.setFont(d_func()->font);
    +        }
    +
             p.drawControl(QStyle::CE_DockWidgetTitle, titleOpt);
         }
     }
    

Log in to reply