How to show single image as background in label
Hi,
I want to show single image in background of QLabel. If the label size is big(say 640 by 480) and if image size is small (say 64 by 64). then background will show so many no of images.
But I want to show only single image with original size in center.
Can anybody suggest me right way to do this.
I am trying following...
Code:
label.setGeometry(0,0,640,480);
QImage img
("/home/nirav/img.png");
palette.
setBrush(label.
backgroundRole(),
QBrush(img
));
label.setPalette(palette);
label.show();
Nirav
"Your suggestion would be a great help for me"
Re: How to show single image as background in label
Re: How to show single image as background in label
Quote:
Originally Posted by
nrabara
Hi,
I want to show single image in background of QLabel. If the label size is big(say 640 by 480) and if image size is small (say 64 by 64). then background will show so many no of images.
But I want to show only single image with original size in center.
Can anybody suggest me right way to do this.
I am trying following...
Code:
label.setGeometry(0,0,640,480);
QImage img
("/home/nirav/img.png");
palette.
setBrush(label.
backgroundRole(),
QBrush(img
));
label.setPalette(palette);
label.show();
Nirav
"Your suggestion would be a great help for me"
Pls try this.
1. You need to use a frame.
2. Put QLabel in the frame.
3. Set your image as QPixmap to that label.
4. Set the Alignment Center (HCenter | VCenter)
5. Set Pixmap scaling to content turned off.
Re: How to show single image as background in label
I have tries as per your suggestion.
Code:
QImage img
("/home/nirav/img.png");
frame.setGeometry(0,0,250,250);
frame.show();
label.setGeometry(0,0,200,200);
pixmap = pixmap.fromImage(img);
palette.
setBrush(label.
backgroundRole,
QBrush(pixmap
));
label.setPalette(palette);
label.show();
but still I am getting some many no of images in label .
I thing this happens because when I create a object of QBrush by passing Pixmap as argument in constructor it takes Qt::TexturePattern. that's way I am getting no of image instead of single one.
This Qt:: TexturePattern is default for QBrush::QBrush(const QImage & img) & QBrush::QBrush(const QPixmap & pixmap)
Can anybody help me solve this problem & how to show a single image in background instead of so many images.
Suggestion would be appreciated.
Re: How to show single image as background in label
Quote:
Originally Posted by
nrabara
but still I am getting some many no of images in label .
I thing this happens because when I create a object of QBrush by passing Pixmap as argument in constructor it takes Qt::TexturePattern. that's way I am getting no of image instead of single one.
What a surprise. Use QLabel::setPixmap()!
[Solved] How to show single image as background in label
Yes, QLabel::setPixmap() .
Thanks .