Graphical artifacts in QPushButton
-
wrote on 4 Dec 2014, 09:13 last edited by
Hi,
I have class of buttons that inherits QPushButton. I set style of this button by setting setStyleSeet method.
I have QWidget container that is parent for my buttons and for other QWidget fullWidget. Buttons have its own position, but fullWidget is expanding to its parent. Buttons are raised over fullWidget. But when I do this (raise) the artifacts is showing. For example, buttons have rounded corners, but after raising they have grey background!http://oi61.tinypic.com/1p9ulz.jpg()! - image is painted by me, it's only to show what is wrong.
Any idea how to fix it?
-
wrote on 4 Dec 2014, 18:24 last edited by
I believe that is just the frame in the background of the button. Once you style the button, you have to basically redo everything that the default button style has unless you just change the palette properties.
To fix the gray background, you can make the background of the button transparent (but not the frame with the rounded edges and text).
So you can add to your stylesheet:
@
QPushButton {
"background:transparent;"
...
...
}
@or you can set the background to translucent:
@
button->setAttribute(Qt::WA_TranslucentBackground);
@ -
wrote on 8 Dec 2014, 06:35 last edited by
I have sth like this:
@
button->setStyleString("QPushButton{" +
"padding: " + QString::number(width/3) + "px;" +
"border-radius: " + QString::number(radius/5) + "px;" +
"background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, " +
"stop: 0 #3d94f6, stop: 1 #29569e);" +
"background: transparent" +
"color: white;" +
"font-family: arial;" +
"font-size: " + QString::number(fontSize) + "px;" +
"font-weight: bold" +
"}" +
"QPushButton:hover{" +
"border: 2px solid black;" +
"border-radius: " + QString::number(radius/4) + "px;" +
"background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, " +
"stop: 0 #29569e, stop: 1 #3d94f6);" +
"}"+
"QPushButton:checked{" +
"border: 3px solid black;" +
"border-radius: " + QString::number(radius/3) + "px;" +
"background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, " +
"stop: 0 #29569e, stop: 1 #3d94f6);" +
"}");@
I tried that two methods:
@
QPushButton{
"background:transparent;"
...
...
}@
and also
@
button->setAttribute(Qt::WA_TranslucentBackground);
@
but it didn't work (nothing changed)
1/3