Background color in StackedWidget



  • I have a Stacked widget where I have an image loaded on the main page that is used as background for this page (styleSheet: image ...). On a second page I have another ui loaded (as class) which has a WebView and some buttons.

    I am trying to have a simple gray background on the second page but I don't get it. Whatever I do, I see the image from page 1 in the background, or I see the colored background only upon first opening of page 2 and not subsequently, or it changes the scroll bar of the WebView as well.
    Where do I have to set this color? In the second ui or on in the first ui on the second page of the StackedWidget? What does inherit to and from what ?!? I feel like I tried every option to no avail.



  • Did you do setAutoFillBackground?



  • AutoFillBackground is unchecked (everywhere) and not set from code either.
    Do I have to set it ... and where?



  • For the widget on the second page it should be true.



  • Thanks a lot. That basically works.
    Unfortunately, I'm stuck again. What I could not add, is some color to it. As soon as I add color with a sytlesheet to the same widget it is either not applied, or only once and then again overwritten by the image of the main page. What am I doing wrong?
    I am still trying to understand the logic behind all this.



  • I am not sure about that. At least you should check if your widget works with the stylesheet but background color normally works on all of them.



  • If I have AutoFillBackground checked for the widget on the second page it works with some default color, as long as I don't have any stylesheet options on this widget or the ui loaded on this page.


  • Moderators

    [quote author="McLion" date="1350639690"]I have a Stacked widget where I have an image loaded on the main page that is used as background for this page (styleSheet: image ...). On a second page I have another ui loaded (as class)[/quote]-Is your main page a standalone QWidget? If not, you can't apply a style sheet to it -- you'll be applying the style sheet to the whole QStackedWidget (i.e. all pages will acquire the style sheet)- Edit: I need to think more before posting... :P



  • Seems to be it.
    I have applied the style sheet image directly to the first page (QWidget).
    I have:
    @- stacked widget

    • page1 (where I have applied the style sheet image)
      • button ..
      • button ..
        ...
    • page2 (where I only want a plain color background)
      • WebBrowser (ui, class)@

  • Moderators

    Gah, ignore my last post... of course all QStackedWidget pages are QWidgets themselves... I'm not sure what I was thinking, sorry.

    But anyway, this sounds like a bug. It doesn't make sense that a style sheet applied to one widget would also transfer to other widgets (except for its children). Would you like to file a report at https://bugreports.qt-project.org ?

    In the meantime, maybe you can try one of the following approaches:

    Implement your first page as a separate widget, create a blank page in your original stacked widget, and promote the blank page to your new "first page".

    Apply the style sheet through C++ code instead of through Designer?

    I've done (1) before and can vouch that it works, but I don't know if (2) will work.



  • Thanks a lot for your suggestion .. I'll try this at a later point. I'll simply "cover" all of the background for the moment.
    I am rather new to Qt (and new to C++, though experienced in C for years) and I have to finish this current project within some hours for a demo on Monday. As you could maybe see from some other post in this forum I have some more important issues to solve like the signal/slot linking to another ui that just don't works.



  • Maybe you can paste your piece of code here. Sometimes one cannot see the forest because of all the trees. ;)



  • I'd happily do this .. if I'd know which parts. Because the ui has been created in Designer and not by code there's not much that can be posted to show the ui setup. That's why I tried to show the stackedWidget arrangement some post ago.

    I'll implementing a "workaround" here because that's for a demo (product show) only and not for a series product.
    Thanks for all of your help anyway .. it's highly appreciated!



  • You can post the ui file from the designer or the generated header if possible.



  • Is there a way to attach files to posts ?!?



  • I don't think so. If it is too big you can maybe shape it down to just the QStackWidget parts.


Log in to reply
 

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