Results 1 to 6 of 6

Thread: how to change background of mainwindow with image

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default how to change background of mainwindow with image

    hi
    how to make a image as a background for mainwindow.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to change background of mainwindow with image

    J-P Nurmi

  3. #3
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: how to change background of mainwindow with image

    And an extra question:

    My main screen is a QWidget. I can set the background image with a style sheet containing the following:

    Qt Code:
    1. QWidget#myMainWindow
    2. {
    3. background-image: url(../data/my_background.png);
    4. }
    To copy to clipboard, switch view to plain text mode 

    The trouble is that my main window has a geometry of 0,0,1024,768, which matches the dimensions of the background image. However, if the user re-sizes the window to larger than that, the background image tiles to fill the background. This is visually ugly.

    What I want is for the background image to automatically scale itself, like a QLabel with the ScaledContents flag set to True.

    So far I have failed to find any way of doing this. I even tried making a huge QLabel in the background, but could not force Qt Designer to place buttons and things on top of the QLabel.

    Is there any way to make an automatically scaling background?

  4. #4
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: how to change background of mainwindow with image

    hi
    i have tried changing background color using style sheets and it works

    Qt Code:
    1. this->setStyleSheet("background-color:red");
    To copy to clipboard, switch view to plain text mode 

    if i try to change background image it does not work

    Qt Code:
    1. this->setStyleSheet("background-image: url(:/icon/wave.png)");//does not work
    To copy to clipboard, switch view to plain text mode 

    or
    Qt Code:
    1. this->setStyleSheet("QWidget{background-image: url(:/icon/wave.png)}");//does not work
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: how to change background of mainwindow with image

    For QWidget and QDialog you should reimplement paintEvent() and do your image painting there as I remember
    C++ & AMD forever

  6. #6
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to change background of mainwindow with image

    I'm not very sure. But try like
    qApp->setStyleSheet("QWidget{background-image: url(:/icon/wave.png)}");
    Hope it ll work.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

Similar Threads

  1. Replies: 3
    Last Post: 18th May 2012, 10:12
  2. No Background image showed
    By jiveaxe in forum Installation and Deployment
    Replies: 2
    Last Post: 30th December 2007, 13:25
  3. Setting background image of QFrame
    By Claymore in forum Qt Programming
    Replies: 2
    Last Post: 12th February 2007, 19:50
  4. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 06:25
  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.