Results 1 to 5 of 5

Thread: QWidget background

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QWidget background

    Hi,
    I have adopted two widget in my scene,basically i have a view(qgraphicsview) -> scene(qgraphicsscene) and in the scene i have two qwidget derived class drawing some paint and buttons ,the problem i am facing is that that i have set the background of my view from a jpeg file ,and i want the whole background of window to be from that jpeg file ,but due to two widgets i am also seeing some gray area as surronded by the widget..
    hope i am clear

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWidget background

    did you (not) set QWidget::autoFillBackground()?

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

    salmanmanekia (23rd July 2008)

  4. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget background

    i am setting the autoFillBackground() and then setting palette by setPalette(const QPalette) ,this is how i am trying to do this but it throws an error .

    Qt Code:
    1. QPalette *palette;
    2. setAutoFillBackground(TRUE);
    3. palette->setBrush(QPalette::Window,QPixmap(BACKGROUND_DIR_LOCATION));
    4.  
    5. setPalette(palette);---->it throws error here
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 27th July 2008 at 13:30. Reason: missing [code] tags

  5. #4
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget background

    i have solved it,not a big thing...jus not declare palette as pointer..

    Qt Code:
    1. QPalette palette;
    2. palette.setBrush(this->backgroundRole(), QBrush(QImage("backgroundImage.jpg")));
    3.  
    4. this->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 27th July 2008 at 13:31. Reason: missing [code] tags

  6. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget background

    Of course....
    Qt Code:
    1. QPalette *palette;
    2. setAutoFillBackground(TRUE);
    3. palette->setBrush(QPalette::Window,QPixmap(BACKGROUND_DIR_ LOCATION));
    4.  
    5. setPalette(palette);---->it throws error here
    To copy to clipboard, switch view to plain text mode 

    You didnt create an instance of palette like -
    palette = new QPalette();

  7. The following user says thank you to aamer4yu for this useful post:

    salmanmanekia (23rd July 2008)

Similar Threads

  1. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  2. background image for QWidget
    By raman_31181 in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2008, 11:13
  3. Replies: 10
    Last Post: 17th August 2006, 15:12
  4. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44
  5. Replies: 1
    Last Post: 5th April 2006, 16:44

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
  •  
Qt is a trademark of The Qt Company.