Problem with central widget and style sheet



  • Hello, i have a problem

    you can see the problem in the videos below, in the first video i don't set style sheet to my central widget

    http://ubuntuone.com/3dly9V6LCwPBWMjnMYxcdr

    in the second video i set style sheet to my central widget

    http://ubuntuone.com/4lyf6EEaAmWL8DWS6N44Gi

    the style sheet i set is a backgound image
    @QWidget#mainwidget {
    background-image: url(/home/chris/.config/coyote/themes/dark/images/general_background.png);
    }@

    i have set mainwidget as ObjectName to the widget

    the problem as you can see is that when i set style sheet the other styles sheets at the other widgets doesn't change
    also the background of the central widgets doesn't change accordind to the image

    any idea?



  • Your way won't working. If you use Qt Designer - you can select centralWidget and add dynamic value to it (green cross at Object Inspector topbar) with bool value - true. And in your .qss:
    @
    QWidget[somevalueiaddedbefore=true] {
    background-image: url("/home/chris/.config/coyote/themes/dark/images/general_background.png");
    /* or /
    background-image: url(":/themes/dark/images/generalBackground.png"); /
    qrc-way */
    }
    @
    But I recommend you to use resources instead of full way (like the second way). Read about resources on the Net.

    UPD: Or you can do simply, just use objectName as ID:
    @
    QWidget#centralWidget {
    background-image: url("/home/chris/.config/coyote/themes/dark/images/general_background.png");
    }
    @



  • i am not using qt designer so i can't use the first method.
    i am already using objectName as ID

    @QWidget#mainwidget@ from the code in my first post

    any idea?



  • I can't understand why the centralWidget's background doesn't change..



  • My suggestion would be to get other forms of a stylesheets working on your central widget first...go to the designer, click on your central widget in the object list, and click the stylesheet interface. Add this line:

    @
    #centralWidget {
    color: rgb(85, 255, 0);
    }
    @

    or if its name is mainWidget then
    @
    #mainWidget {
    color: rgb(85, 255, 0);
    }
    @

    See if your button text colors changes...if so, then its something wrong with your stylesheet command. I just tried it and it worked for me.



  • with the color it works

    so there is a problem with my style sheet, hmm, i tried moving my image in the project's folder but nothing

    just a correction, for the backgound color the style sheet needs to be
    @#centralWidget {
    background-color: rgb(85, 255, 0);
    }
    @ :)



  • As I said above, that should change the text color on the button. Not the background color.



  • i don't have any buttons, the central widget is a widget contain the final layout of my application so that i can use QMainWindow.setCentralWidget()



  • Ok, well I was just clearly stating you should try something else out other than the style sheet you used to error check you previous configuration, buttons or no buttons, text or no text.

    Good luck.



  • thanks for your help, with a search a see that generally there is a problem with centralwidget/mainwindow and background image


Log in to reply
 

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