Results 1 to 4 of 4

Thread: set backgorund image on main window

  1. #1
    Join Date
    Jan 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default set backgorund image on main window

    i have a problem to set a background image on main window. i discovered that qt can use css to give some appearance. for my application i have created the image and put in into folder name image in source code folder. i have successfully code the css syntax
    Qt Code:
    1. QWidget#centralwidget { background-image: url(:/image/mainbg2.png); background-repeat: repeat-x; }
    To copy to clipboard, switch view to plain text mode 
    when I click apply there nothing happen on my main window. my question here is does this thing work on the spot or we need to compile first to see the result?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: set backgorund image on main window

    Yes, you need to recompile, because the resource will be compiled and embedded in the application. And how else would you be able to set a stylesheet for a widget without setStylesheet and recompiling?

  3. #3
    Join Date
    Jan 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: set backgorund image on main window

    owh... actually I used qt designer and I did set the style through it. Pardon the code I've paste before. Its a wrong code to be put into through designer, Ive fixed it.

    Now I have some more question, do we need to put the image file into resource (.qrc file)?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: set backgorund image on main window

    Just add a reference to it(it's path). It will be embedded in the application at compile time.

Similar Threads

  1. access main window from function
    By eric in forum Qt Programming
    Replies: 6
    Last Post: 19th January 2008, 21:29
  2. minimizing main window
    By eric in forum Qt Programming
    Replies: 4
    Last Post: 28th November 2007, 16:54
  3. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 15:40
  4. Replies: 15
    Last Post: 23rd March 2007, 16:16
  5. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21

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.