QT如何设置窗口背景图片拉伸填充窗口?

QT如何设置窗口背景图片拉伸填充窗口?

以下内容引用自:百度知道:网址中frostweek的回答:{
1,创建QPixmap指针;

QPixmap *pixmapBackground;

pixmapBackground=new QPixmap(":/skin/myPicture.png");

2,定义paintEvent()函数;
3,在paintEvent()函数中,调用drawPixmap()。

painter.drawPixmap(100,50,400,300,*pixmapBackground);

前两个参是图片的左上角x、y坐标;后两个参就是你要设定的图片缩放尺寸了。}
但是这是一个固定大小的窗口:不能随窗口缩放
若想跟随窗口缩放我们需要知道窗口大小:

获取窗口位置和大小

以下内容引用自:努力减肥的小胖子5的个人博客:网址

//窗口左上角的位置(含边框)
qDebug() << this->frameGeometry().x() << this->frameGeometry().y() << ;//1
qDebug() << this->x() << this->y();//2
qDebug() << this->pos().x() << this->pos().y();//3
//窗口的宽度和高度(含边框)
qDebug() << this->frameGeometry().width() << this->frameGeometry().height();
//窗口左上角的位置(不含边框)
qDebug() << this->geometry().x() << this->geometry().y();
//窗口的宽度和高度(不含边框)
qDebug() << this->geometry().width() << this->geometry().height();//1
qDebug() << this->width() << this->height();//2
qDebug() << this->rect().width() << this->rect().height();//3
qDebug() << this->size().width() << this->size().height();//4

posted @ 2020-04-10 13:32  糜世  阅读(2738)  评论(0编辑  收藏  举报