Results 1 to 3 of 3

Thread: Background image on a combined widget list

  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Background image on a combined widget list

    Hi, i'm trying to set a background image on a combined QWidget using stylesheets.
    For combined QWidget i mean a qwidget A in which there is a layout containing some widgets, for example:

    I have the class A that extends QWidget, in te constructor i have the following code to create a combined widget:
    Qt Code:
    1. hLayout = new QHBoxLayout;
    2. vLayout = new QVBoxLayout;
    3.  
    4. labelGroup->adjustSize();
    5. labelIco->adjustSize();
    6. labelIcoReceived->adjustSize();
    7. labelTxt->adjustSize();
    8. labelTime->adjustSize();
    9.  
    10. hLayout->addWidget(labelIcoReceived);
    11. hLayout->addWidget(labelGroup);
    12. hLayout->addWidget(labelIco);
    13. hLayout->addWidget(labelService);
    14. hLayout->addWidget(labelTime);
    15. vLayout->addLayout(hLayout);
    16. vLayout->addWidget(labelTxt);
    17.  
    18. setLayout(vLayout);
    19. setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum);
    20. adjustSize();
    To copy to clipboard, switch view to plain text mode 

    If i try to append

    setStyleSheet("background-color: yellow");
    The result is the following:

    widgets.JPG

    And obviously i don't want this, i wan't to spread the color all over the widget.
    I would like to use stylesheets because i wan't to add a scalable border image to the background like the one explained here and showed here:


    How can i do this?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Background image on a combined widget list

    It is most likely you have to set setAutoFillBackground to true. Then it should work. Also you might want to set the style sheet only for the widget, not for all children also.

  3. #3
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Background image on a combined widget list

    Solved!
    I have modified my qwidget A declaration, making it extends QFrame instead of QWidget and then using:

    Qt Code:
    1. setStyleSheet("A{ background-color: yellow }");
    To copy to clipboard, switch view to plain text mode 
    in order not to propagate the style to children.

    Thanks

    P.S. This site helps to overcome these kind of problems. It explains how to set backgrounds on widgets of frames.

Similar Threads

  1. Replies: 10
    Last Post: 10th November 2010, 04:12
  2. Setting background image for Central Widget
    By xfurrier in forum Qt Programming
    Replies: 8
    Last Post: 25th February 2010, 11:14
  3. how to change BackGround image on a stacked widget
    By mcrahr in forum Qt Programming
    Replies: 3
    Last Post: 10th February 2010, 09:38
  4. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 16:40
  5. Background image and semitransparent widget
    By asieriko in forum Qt Programming
    Replies: 3
    Last Post: 20th August 2007, 17:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.