QDialog with qss-stylable subcontrols (title and close button)
I need to create QDialog-based control with custom title and close button. Simple way is to add some methods for controlling title and close button, but I want to have a possibility to style subcontrols through qss ::title and ::close-button selectors, which are already defined for QDockWidget. I want to do something like the following:
Code:
MyDialog::title {
subcontrol-origin:margin;
subcontrol-position:left;
color: white;
.... etc....
}
MyDialog::close-button {
subcontrol-origin:margin;
subcontrol-position:right;
image: url(./img.png);
.... etc....
}
Is it possible at all ?
Re: QDialog with qss-stylable subcontrols (title and close button)
No, it's not. If you want to control the title, use QWidget::setWindowTitle(). As for the close button - it's part of the window manager and not your application so you can't modify it.
Re: QDialog with qss-stylable subcontrols (title and close button)
Thank you for reply, but I'm speaking about custom title and close button. They are implemented by me and all I want is possibility to style them due qss as it is done with QDockWidget. As a temporary workaround I found possibility to "address" this control with their object names, for example
Code:
MyDialog#title {
.........
}
or
MyDialog#closeButton {
...
}
but this approach is less clear than MyDialog::title and it seems subcontrol-position and subcontrol-origin qss properties are not working, so question is still opened.
And I've got one more question: How to add :hover qss state to QWidget/QDialog subclass ?
Re: QDialog with qss-stylable subcontrols (title and close button)
You can't add your own style selectors to widgets. You can try to address QDialog:hover or MyDialog:hover but make sure first the widget receives hover events at all. But if the :hover state is not handled by QDialog, there is nothing you can do.
Re: QDialog with qss-stylable subcontrols (title and close button)
Probably I can't. But I've already added ability to be stylable with
"border-image" and "border-width" qss properties, which are not allowed for QDialogs according to the docummentation. All I need to do was:
Code:
{
opt.init(this);
style
()->drawPrimitive
(QStyle::PE_Frame,
&opt,
&p,
this);
}
So, I'll try to continue experiments just in case if solution is not harder than code above. Probably deep investigation of QDockWidget internals will help.
Re: QDialog with qss-stylable subcontrols (title and close button)
It's your time, not mine. If you want to waste it - go ahead. The above works because you ask the style to draw the primitive for you. If you'd like :title to work, you'd have to again ask the style to draw the respective primitive for you and so your title would look like QDockWidget's which is probably not what you want, especially that the title is not drawn by some widget styles at all.