Results 1 to 5 of 5

Thread: background-image on a set of widgets

  1. #1
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default background-image on a set of widgets

    Hello,
    I've created a widget and I want to have an image on its background. But when I try to do it, the image is also draw on each child widget.
    I've tried with designer but It doesn't work either.
    I've been able to not drawing again the image on the child widgets, drawing a new image on them.

    I'll paste the code and show you some shoots.

    Qt Code:
    1. #include <QApplication>
    2. #include <QListWidget>
    3. #include <QGridLayout>
    4. #include <QWidget>
    5.  
    6. int main(int argc, char ** argv)
    7. {
    8. QApplication app( argc, argv );
    9.  
    10. QWidget widget(0);
    11. widget.setStyleSheet("background-image: url(/home/asier/imagenes/fondos/14999-Midsommarblomster.jpg)");
    12.  
    13. QGridLayout *leftLayout = new QGridLayout();
    14. leftLayout->setSpacing (0);
    15.  
    16. for( int row = 0; row < 2; row++ ) {
    17. for( int col = 0; col < 2; col++ ) {
    18.  
    19. QListWidget *wi = new QListWidget();
    20. wi->setStyleSheet("background-image: url(/home/asier/imagenes/fondos/Abetal.jpg);background-attachment: fixed");
    21.  
    22. leftLayout->addWidget( wi, row +1, col );
    23.  
    24. leftLayout->setRowStretch( row + 1, 1 );
    25. }
    26. }
    27.  
    28. widget.setLayout(leftLayout);
    29.  
    30. widget.show();
    31. return app.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 

    In the first shoot you can be how the image is also drawn on each widget, the second shows the image on the background, but with a new one for each widget. And the last one, shows the desinger with blank widgets, but the preview draws again the image for each of them.

    What can I do to have the image on the background, and not on each widget?
    I don't know if It is my fault, is not implemented or if it is a bug?

    Thank you in advance!
    Asier
    Attached Images Attached Images
    Last edited by asieriko; 31st May 2008 at 15:46.

  2. #2
    Join Date
    Mar 2008
    Posts
    52
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: background-image on a set of widgets

    Hi,
    I think this may be help you.
    Better to go for QLabel.you will get any kind of image as back ground.You can set a Qpixmap on Each label prosperity in your each widget on designer itself.

  3. #3
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Re: background-image on a set of widgets

    Hi, Thanks.

    But I need QListViews, I need lists.
    The only problem is that the whole widget background-image is repetated again on each child widget.
    I mean, Transparents Lists that woul make possible to view the image that is in the background.

  4. #4
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Re: background-image on a set of widgets

    I've solved it.
    I don't think this is the best way, but it works.

    As I noticed that when I draw a background on the widgets, the Whole background was not draw on them, I've set a transparent background image for the widgets and It does the trick.

    Qt Code:
    1. wi->setStyleSheet("background-image: url(/home/asier/transparent.png)");
    To copy to clipboard, switch view to plain text mode 

    Now I've to adapt it to a more complex widget. That at the first try does not work. But I hope, it will.
    If you have any other idea for doing this, please tell me.

    Thanks
    Attached Images Attached Images

  5. #5
    Join Date
    Sep 2008
    Location
    Munich
    Posts
    32
    Thanked 8 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: background-image on a set of widgets

    It would have been easier using http://doc.qt.nokia.com/4.7-snapshot...ackground-prop. Widgets don't draw their background for performance reasons. Setting a stylesheet will automaticall turn this on for my knowledge.

Similar Threads

  1. Replies: 3
    Last Post: 18th May 2012, 10:12
  2. Setting background image of QFrame
    By Claymore in forum Qt Programming
    Replies: 2
    Last Post: 12th February 2007, 19:50
  3. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 06:25
  4. Grabbing widget's background
    By jpn in forum Qt Programming
    Replies: 4
    Last Post: 14th May 2006, 07:58
  5. [QT4.1.1 XP] background image
    By incapacitant in forum Newbie
    Replies: 3
    Last Post: 1st March 2006, 13:02

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.