Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize the titlebar of a QMdiSubWindow with qss?

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 ?

like image 806
devBox Avatar asked Jan 09 '11 13:01

devBox


1 Answers

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.

like image 69
Iuliu Avatar answered Nov 08 '22 20:11

Iuliu