How to customize the titlebar of a QMdiSubWindow with qss?
Asked Answered
H

1

7

I'd like to customize the titlebar of a QMdiSubWindow. For that I use a qss.

QMdiSubWindow { border: 1px solid #000000; background: #000000 }
QMdiSubWindow:title { background: #000000 }

The problem is when applying this qss, the window icons disappear. I know it's possible to define these icons in qss for a QDockWidget

QDockWidget { ... titlebar-close-icon: url(myCloseIcon.png); ... }

However I can't find a way to define it for a QMdiSubWindow. Perhaps this way doesn't exists. Do you know if it's possible ?

Hydrotropism answered 9/1, 2011 at 13:36 Comment(1)
This is an issue for many years now. Are there any workarounds to style MDI childs?Coventry
U
2

As of Qt 5.2 you can't; haven't checked 5.3 but AFAIK they didn't changed anything in the QMdiArea/QMdiSubWindow in the 5.3 release.

The easiest solution you have is to use QCommonStyle and paint the title bar using QPainter. For more info on that see the QCommonStyle and QStyle documentations. Please note that it is recommended to derive QCommonStyle and not QStyle for your style class. QCommonStyle inherits QStyle so you won't loose anything.

And if you want to achieve more complex effects such as drop shadow on the sub window then the only option you have left here is to derive QMdiSubWindow and QMdiArea, call QWidget::setWindowFlags(Qt::FramelessWindowHintflag) on the QMdiSubWindow derived class and implement from scratch your own subwindow with your own title bar. You can then define your own Q_PROPERTYs of type QColor and access those from QSS like exposed here in order to customize titlebar colors from QSS.

Another option would be to create a new MDI area widget from scratch but I don't think this would be applicable in your case. If you just need to customize the title bar using a custom style is the best approach you can tackle. If in trouble examples could be provided as an edit to this post.

But if you want to customize the standard QMdiSubWindow using just QSS, unfortunately it is not possible for the moment.

Ure answered 30/12, 2014 at 23:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.