Why does background-image displays on top of background-color in QPushButton?



  • Hi,

    I set the stylesheet property of my MainWindow to load an image for the background of the window with setStyleSheet(), but that caused the QPushButtons in the entire project to display the same image as background, because I pressume setting the parent window's background-image property is automatically passed to the QPushButton's properties.
    So , since I wanted the buttons to show as background a color and not an image, I set the background-color of the QPushbuttons to a color, but the color shows behind the image.
    Can someone tell me how I could solve this problem.
    I just want my buttons to show a background color not an image, but setting the background-image property on the MainWidnow makes the buttons adopt the image.

    thank you

    -Malena



  • Hi,

    I assume, that the style sheet is incorrect.

    if you set a a "selector":http://doc.qt.nokia.com/4.7/stylesheet-syntax.html only widgets which fit thge selector get the property.

    e.g.

    @
    QTextEdit, QListView
    {
    background-image: url(draft.png);
    }
    @

    sets the beckground image to all QTextEdit, QListView and from those classes derived classes.

    @
    QWidget
    {
    background-image: url(draft.png);
    }
    @

    sets the beckground image to all QWidget derived classes, which means to all widgets.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.