Results 1 to 4 of 4

Thread: [QT4.1.1 XP] background image

  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default [QT4.1.1 XP] background image

    I try to set the background of a widget to an image as indicated in Assistant in the
    Porting to QT4 of setPaletteBackgroundPixmap :
    Qt Code:
    1. QWidget *widget = new QWidget;
    2. QPixmap pixmap(":/images/bArchi.png");
    3. QPalette palette;
    4. palette.setBrush(widget->backgroundRole(), QBrush(pixmap));
    5. widget->setPalette(palette);
    6. setCentralWidget(widget);
    To copy to clipboard, switch view to plain text mode 

    I played around with many combinations of the above code, but nothing will show my
    image. The background remains unchanged...


  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [QT4.1.1 XP] background image

    Is the path to the resource image correct? Try using a file path (preferrably non-relative one) first.

  3. The following user says thank you to wysota for this useful post:

    incapacitant (2nd March 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [QT4.1.1 XP] background image

    Qt Code:
    1. QPixmap pixmap("C:/Qt/test/chart/images/bArchi.png");
    To copy to clipboard, switch view to plain text mode 

    Unfortunately the absolute path has the same negative result.

  5. #4
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [QT4.1.1 XP] background image

    correct answer was simple but took me a while to find it :
    to change this window's background :

    Qt Code:
    1. QPalette palette;
    2. QPixmap pixmap = QPixmap("./images/bBackground.png");
    3. palette.setBrush((this)->backgroundRole(), QBrush(pixmap));
    4. (this)->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 



Similar Threads

  1. Replies: 3
    Last Post: 18th May 2012, 10:12
  2. How to stretch background image used in brush-palette
    By Hookem in forum Qt Programming
    Replies: 5
    Last Post: 24th December 2008, 17:03
  3. Replies: 15
    Last Post: 23rd March 2007, 16:16
  4. Setting background image of QFrame
    By Claymore in forum Qt Programming
    Replies: 2
    Last Post: 12th February 2007, 19:50
  5. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 06:25

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.