Styling a QDockWidget's title
-
Hi :-)
I used to set a style sheet for my program's
QDockWidget
s 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!
-
Hi,
Sounds like it could be a regression.
On what platform do you observe that ? Did you check on another ?
-
No need to upgrade. It's a regression between 5.10.1 and 5.11. Can you please create a bug report?
-
No need to upgrade. It's a regression between 5.10.1 and 5.11. Can you please create a bug report?
@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?!
-
@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); } }