Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: How to set background of application??

  1. #1
    Join Date
    May 2009
    Posts
    9
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default How to set background of application??

    Hi,

    I am new bie to Qt. I want to set background (image) to my application. how can i do that??
    I know QPixmap load the image but i dont know how to set it as background.

    I am working on Qt for S60(Symbian OS). Using 4.5.0-garden release.

    Thanks,
    kamlesh.

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

    Default Re: How to set background of application??

    Take a look at QPalette.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set background of application??

    hi friends ,
    i am little confused with this question
    which one is best to set the background ..
    QPalette or StyleSheet...?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set background of application??

    using QPalette is faster, but you still can use Style Sheets.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set background of application??

    thanks for the reply first ...
    in a graphicsView i am animating an item .. when mouse hover over the item it will scale ... normally it works perfectly untill i setStyleSheet->background color .. the animation becomes very slow .. so i switch to QPalette and now it works fine ... why ...?

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set background of application??

    as I said, QPalette is faster then Style Sheets, because when you use Style Sheets all information about style must be parsed and this process takes a time.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    wagmare (5th May 2009)

  8. #7
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set background of application??

    thanks .. i get it ...

  9. #8
    Join Date
    May 2009
    Posts
    9
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: How to set background of application??

    Quote Originally Posted by wysota View Post
    Take a look at QPalette.
    AFAIK QPalette will help to change colors of background, not to set image as background. I want to set image as background.

  10. #9
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set background of application??

    then you need to reimplement QWidget:: paintEvent and using QPainter::drawPixmap draw it.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. #10
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to set background of application??

    Quote Originally Posted by kamlesh.sangani View Post
    AFAIK QPalette will help to change colors of background, not to set image as background. I want to set image as background.
    use styleSheet background-image:

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

    Default Re: How to set background of application??

    Quote Originally Posted by kamlesh.sangani View Post
    AFAIK QPalette will help to change colors of background, not to set image as background. I want to set image as background.
    Funny, I wonder what QPalette::setBrush() is for then

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv){
    4. QApplication app(argc, argv);
    5. QPalette p = w.palette();
    6. p.setBrush(QPalette::Base, QPixmap("/usr/share/wallpapers/Air/contents/images/1024x768.jpg"));
    7. w.setPalette(p);
    8. w.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    kamlesh.sangani (6th May 2009)

  14. #12
    Join Date
    May 2009
    Posts
    9
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: How to set background of application??

    Fantastic. its worked for me. thanks a lot wysota.

    I ve dont it with slit modification.

    Qt Code:
    1. p.setBrush(QPalette::Background, QPixmap("C://01.jpg"))
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: How to set background of application??

    The role depends on the widget so with a listview you have to use Base while for a frame you'd use Window or Background.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #14
    Join Date
    Jun 2009
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set background of application??

    But with palette if you have labels,buttons... you cover with the background image,isn't it?
    How can it solve it?

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

    Default Re: How to set background of application??

    You cover what with what?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #16
    Join Date
    Jun 2009
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set background of application??

    I have set some buttons in a window and now I have to insert an image as a background.
    I´m trying to do as you say but now the buttons don't appear.

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

    Default Re: How to set background of application??

    Please show us the code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #18
    Join Date
    Jun 2009
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set background of application??

    It was a problem of my programm. I have solved it!

    But, if I maximize the window , the image appears once,twice... and it doesn´t suit to the window. My image is .bmp

    QPalette pal = widget.palette();
    pal.setBrush( QPalette::Window, QPixmap("image.bmp"));
    widget.setPalette( pal );

  21. #19
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set background of application??

    Quote Originally Posted by IRON_MAN View Post
    It was a problem of my programm. I have solved it!

    But, if I maximize the window , the image appears once,twice... and it doesn´t suit to the window. My image is .bmp

    QPalette pal = widget.palette();
    pal.setBrush( QPalette::Window, QPixmap("image.bmp"));
    widget.setPalette( pal );
    re implement resizeEvent and resize your image to desired size

    Qt Code:
    1. void MyWidget::resizeEvent(QResizeEvent* e)
    2. {
    3. static QPixmap pix("image.bmp");
    4. QPalette pal = widget.palette();
    5. pal.setBrush( QPalette::Window, pix.scaled(e->size(),...,...) );
    6. widget.setPalette( pal );
    7. }
    To copy to clipboard, switch view to plain text mode 

  22. #20
    Join Date
    Jun 2009
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set background of application??

    Thanks a lot!

Similar Threads

  1. How to detect a running application
    By yogesh in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2009, 10:22
  2. Run application in background
    By raulftang in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 24th April 2007, 09:29
  3. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37
  4. Replies: 3
    Last Post: 8th December 2006, 18:51
  5. Background QT application.
    By Thrantor in forum Qt Programming
    Replies: 4
    Last Post: 12th September 2006, 22:29

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.