stylsheet is not working in main widget



  • qt 5.11.1 , linux.
    i applied this stylesheet in the main widget .

    QWidget {
    background-color: #1C2836;
    color: #ffffff;
    }
    

    the widget shows fine in designer.

    0_1530414137386_b3.png

    after build i am seeing it is only applied in the label ,buttons not in the main widgets backgrounds and SPACING .
    0_1530414179648_b2.png

    when add another widget in the main widget and apply stylesheet on that secind widget it works fine. like this

    0_1530414318544_b1.png



  • Like in List of Stylable Widgets said, QWidget only supports 3 style properties: background, background-clip, background-origin.
    You might using QPalette:

    m_myWidget = new QWidget(this);
    m_myWidget->setGeometry(0, 0, 300, 100);
    QPalette pal = palette();
    
    // set black background
    pal.setColor(QPalette::Background, Qt::black);
    m_myWidget->setAutoFillBackground(true);
    m_myWidget->setPalette(pal);
    m_myWidget->show();
    
    

    from: https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget



  • @nkiy

    i am not using QPalette . if i wanted to use qpalette i have do alot of work.

    i was using stylsheet for each widgets and it works fine then .but i want to set one stylesheet in main widget so it is a better and perfect way.
    but it is giving me this.


  • Qt Champions 2017

    Hi
    Try to set
    setAutoFillBackground(true); for Wbattery
    (its a property so you can do in Designer)
    Also, did you set the layouts margins to zero- so there is no spaces ?
    alt text

    I think what you are seeing is once you use wBattery in app,
    it get more space, so layout spaces the items. Widgets have
    no background pr default so you look through and see the other window under it.

    Depending on what you need, you might also want to set its maximumsize so it stays like in Designer. Else when you insert in some other widget, it might be bigger if more space for it.
    alt text
    Only do this if goal is to stay same size even when mainwindow resizes.



  • @mrjj

    i need those spaces for looks. so i gess i have to add padding in qstylesheet to get those spaces.

    thanks.


  • Qt Champions 2017

    @saber
    Well the margins for layout works just as well.
    so maybe just setAutoFillBackground look like you want.



  • @mrjj
    any solution for this post
    stylsheet is not working properly


Log in to reply
 

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