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