Stylesheet: using background image for floating DockWidgets
-
Hi,
we use following code in our stylesheet to change the background of dockwidgets whenever they are attached/detached:
QDockWidget { background: transparent; } [floating="true"] { background: #b3ac98; }
The parent uses a border-image, therefore we have the dockwidgets use a transparent background.
We would like to use the same image for the floating/detached dockwidgets as well but they just end up being all black.Is there any regular way to achieve this?
I've seen this: https://stackoverflow.com/questions/10272091/cannot-add-a-background-image-to-a-qdockwidget
but I am not sure if there's a simpler proper way.Thx, Megamouse
-
Hi
Yes if you draw it like
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
then yes. its drawn as plan widget, not a dock :) -
It works perfectly with the method I just explained.
Here the code for anybody interested: (partly taken from original post's source)void paintEvent(QPaintEvent* event) { if (isFloating()) { QStyleOption opt; opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); return; } QDockWidget::paintEvent(event); }
in combination with:
connect(this, &QDockWidget::topLevelChanged, [this](bool/* topLevel*/) { style()->unpolish(this); style()->polish(this); });