PDA

View Full Version : Image as a background



Tomasz
6th December 2010, 09:17
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

high_flyer
6th December 2010, 09:39
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.

Tomasz
6th December 2010, 09:55
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

high_flyer
6th December 2010, 10:05
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.

Tomasz
6th December 2010, 10:35
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

high_flyer
6th December 2010, 14:37
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::paintEvent()), 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.