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.
Re: How to set background of application??
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...?
Re: How to set background of application??
using QPalette is faster, but you still can use Style Sheets. :)
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 ...?
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.
Re: How to set background of application??
Re: How to set background of application??
Quote:
Originally Posted by
wysota
AFAIK QPalette will help to change colors of background, not to set image as background. I want to set image as background.
Re: How to set background of application??
then you need to reimplement QWidget:: paintEvent and using QPainter::drawPixmap draw it.
Re: How to set background of application??
Quote:
Originally Posted by
kamlesh.sangani
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:
Re: How to set background of application??
Quote:
Originally Posted by
kamlesh.sangani
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 :)
Code:
#include <QtGui>
int main(int argc, char **argv){
p.
setBrush(QPalette::Base,
QPixmap("/usr/share/wallpapers/Air/contents/images/1024x768.jpg"));
w.setPalette(p);
w.show();
return app.exec();
}
Re: How to set background of application??
Fantastic. its worked for me. thanks a lot wysota.
I ve dont it with slit modification.
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.
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?
Re: How to set background of application??
You cover what with what?
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.
Re: How to set background of application??
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 );
Re: How to set background of application??
Quote:
Originally Posted by
IRON_MAN
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
Code:
{
pal.
setBrush( QPalette::Window, pix.
scaled(e
->size
(),...,...
) );
widget.setPalette( pal );
}
Re: How to set background of application??