Results 1 to 6 of 6

Thread: QDialog with qss-stylable subcontrols (title and close button)

  1. #1
    Join Date
    Jan 2006
    Posts
    30
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default 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:

    Qt Code:
    1. MyDialog::title {
    2. subcontrol-origin:margin;
    3. subcontrol-position:left;
    4. color: white;
    5. .... etc....
    6. }
    7.  
    8. MyDialog::close-button {
    9. subcontrol-origin:margin;
    10. subcontrol-position:right;
    11. image: url(./img.png);
    12. .... etc....
    13. }
    To copy to clipboard, switch view to plain text mode 

    Is it possible at all ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  3. #3
    Join Date
    Jan 2006
    Posts
    30
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default 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
    Qt Code:
    1. MyDialog#title {
    2. .........
    3. }
    4.  
    5. or
    6. MyDialog#closeButton {
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 

    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 ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  5. #5
    Join Date
    Jan 2006
    Posts
    30
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default 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:

    Qt Code:
    1. void MyDialog::paintEvent( QPaintEvent* event )
    2. {
    3. opt.init(this);
    4. QPainter p(this);
    5. style()->drawPrimitive(QStyle::PE_Frame, &opt, &p, this);
    6. }
    To copy to clipboard, switch view to plain text mode 

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

Similar Threads

  1. Replies: 1
    Last Post: 7th July 2007, 10:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.