PDA

View Full Version : Customizing a dialogs background with QStyle



SebastianBecker
9th September 2009, 07:47
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

yogeshgokul
9th September 2009, 08:27
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 (http://doc.trolltech.com/4.5/stylesheet-reference.html).

SebastianBecker
9th September 2009, 19:21
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

yogeshgokul
10th September 2009, 04:56
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.

Giga
10th September 2009, 07:09
Use QPalette instead.


QPalette palette = dialog.palette();
QLinearGradient gradient(0, 0, 0, 50);
gradient.setColorAt(0, Qt::black);
gradient.setColorAt(1, Qt::white);
QBrush brush(gradient);
palette.setBrush(QPalette::Window, brush);
dialog.setPalette(palette);

yogeshgokul
10th September 2009, 13:11
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.