Results 1 to 6 of 6

Thread: Image as a background

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Image as a background

    Hello!

    Can I use image as a background of widget (for example button)? I mean I've got small image and want it to be tiled on button (like on web page - using small image as a background), and then put on that button other things (text, icon...).

    thanks in advance
    best regards
    Tomasz

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Image as a background

    Yes.
    To do what you described, you will have to override the paintEvent() and set your tile image as brush.
    See QBrush for more details.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Tomasz (6th December 2010)

  4. #3
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Image as a background

    Quote Originally Posted by high_flyer View Post
    To do what you described, you will have to override the paintEvent() [...]
    Ok. I see.
    So I've got one more favour to ask - many times I hear about overriding some functions, but i can't find any nice example how to do it right way. Maybe someone got some link or piece of code how to override and then use that overrided functions of widgets?

    thanks in advance
    best regards
    Tomasz

  5. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Image as a background

    I am not sure I follow.
    When you override a method you do it because you want to add your own functionality to it - so how can someone else give you an example for that?
    You do know what overriding a method is , right?
    But I probably just don't understand your question.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #5
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Image as a background

    I know what override is in theory. When I override paintEvent() then I should write my own painting event (including painting text etc...), right? Or maybe I've got all standard painting inherited from original paintEvent()? I just want to see some example how can I do it on widget. It could be any similar example, and I think then I will be able to do it myself.

    thanks in advance
    best regards
    Tomasz

  7. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Image as a background

    This is out side of the scope of this forum, since this is basic C++ issue.
    In short however, if you call the paintEvent of the mother class(in your case it would be QPushButton:aintEvent()), then you have its functionality too.

    But please don't ask basic C++ questions in these forums, as they are meant for specific help with Qt related issue, where C++ (or what ever language you are using with your Qt) knowledge is assumed.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 1
    Last Post: 25th June 2010, 18:31
  2. background image for QWidget
    By raman_31181 in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2008, 11:13
  3. No Background image showed
    By jiveaxe in forum Installation and Deployment
    Replies: 2
    Last Post: 30th December 2007, 13:25
  4. No Background Image on Example
    By igor in forum Qt Programming
    Replies: 3
    Last Post: 19th January 2007, 12:41
  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.