Background image stretch for QWidget Screen
Is it possible to stretch the background image. Actually I have a image of size 320X480, I want to use this image as background for a QWidget screen with size 360X640.
I tried with the followings:
1). Here the image gets stretched for the screen but a button with another image is loaded along with the Main screen image:
ui->MainScreen->setStyleSheet("border-image: url(:/images/Main-screen.png);");
2). Here the image is not stretched, but displayed as tiles:
ui->MainScreen->setStyleSheet("background-image: url(:/images/Main-screen.png); border: none");
ui->MainScreen->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
ui->MainScreen->setBackgroundRole(QPalette::B开发者_Go百科ackground);
Any suggestions for this....!
Thanks...
I think the reason that your button is getting the same image as the background is because style sheets are applied to child widgets too (I think). After doing the same code you used in #1, try setting the button's style sheet to something else. The child's style sheet should override the parent's style sheet.
Try the following:
ui->MainScreen->setStyleSheet("QMainWindow {border-image: url(:/images/Main-screen.png);}");
This tells Qt to change the background image of all of the QMainWindows in the child tree. from ui->MainScreen. If you do not specify the class type or object name, no filter will be applied, and every child will get the background image.
QWidget#QMainWindow { style; }
#subclass
after mainclass
(QWidget
) sets style to JUST the subclass
It will do exactly what your trying to do.
精彩评论