Results 1 to 6 of 6

Thread: Customizing a dialogs background with QStyle

  1. #1
    Join Date
    May 2009
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Customizing a dialogs background with QStyle

    Hello,

    is there any way to customize the painting of a QDialog? I would like to define a gradient as background and a custom painted frame. I can define this in a stylesheet, but I have to do it in my own QStyle implementation.

    Kind regards,
    Sebastian

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Customizing a dialogs background with QStyle

    Quote Originally Posted by SebastianBecker View Post
    Hello,

    is there any way to customize the painting of a QDialog? I would like to define a gradient as background and a custom painted frame. I can define this in a stylesheet, but I have to do it in my own QStyle implementation.

    Kind regards,
    Sebastian
    You can easily do it using style sheet. Just set the "background" property of QDialog. And set the brush style Qt::RadialGradientPattern.
    For more info click here.

  3. #3
    Join Date
    May 2009
    Posts
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Customizing a dialogs background with QStyle

    Alright, i know that I can do this by using a stylesheet. But how can I do that WITHOUT stylesheets. They are not an option for me since there are some constraints on the project... (Stylesheets take a while for parsing and initialization...)

    Kind regards,
    Sebastian

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Customizing a dialogs background with QStyle

    Take a look here.
    http://doc.trolltech.com/4.5/widgets-styles.html

    In This example the custom style class inherited by QMotifStyle. You can derive your style class by QWindowsStyle or any inbuilt style class depending on your basic requirement.

  5. #5
    Join Date
    Sep 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Customizing a dialogs background with QStyle

    Use QPalette instead.
    Qt Code:
    1. QPalette palette = dialog.palette();
    2. QLinearGradient gradient(0, 0, 0, 50);
    3. gradient.setColorAt(0, Qt::black);
    4. gradient.setColorAt(1, Qt::white);
    5. QBrush brush(gradient);
    6. palette.setBrush(QPalette::Window, brush);
    7. dialog.setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Customizing a dialogs background with QStyle

    Quote Originally Posted by Giga View Post
    Use QPalette instead.
    1. The title of this post says that he want to use QStyle.
    Customizing a dialogs background with QStyle
    2. Qt Docs says:
    For example, the following style sheet specifies that all QLineEdits should use yellow as their background color, and all QCheckBoxes should use red as the text color:

    QLineEdit { background: yellow }
    QCheckBox { color: red }
    For this kind of customization, style sheets are much more powerful than QPalette.

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.