#2
fulltimelink2020-06-11 17:22
|
程序代码:
InstructionHelp::InstructionHelp(QWidget *parent):QDialog(parent)
{
setWindowFlags(Qt::Window|Qt::WindowTitleHint|Qt::CustomizeWindowHint|Qt::WindowCloseButtonHint);
//setFixedSize(400,350);
resize(QSize(300,250));
setWindowTitle(tr("帮助"));
//设置背景图案
QPixmap pixmap_background=QPixmap(":/res/background_sub2.jpg").scaled(this->size());
QPalette palette(this->palette());
palette.setBrush(QPalette::Background, QBrush(pixmap_background));
this->setPalette(palette);
}
{
setWindowFlags(Qt::Window|Qt::WindowTitleHint|Qt::CustomizeWindowHint|Qt::WindowCloseButtonHint);
//setFixedSize(400,350);
resize(QSize(300,250));
setWindowTitle(tr("帮助"));
//设置背景图案
QPixmap pixmap_background=QPixmap(":/res/background_sub2.jpg").scaled(this->size());
QPalette palette(this->palette());
palette.setBrush(QPalette::Background, QBrush(pixmap_background));
this->setPalette(palette);
}
如何让背景随窗口大小变化而缩放。
程序代码:
//重载resizeEvent
void InstructionHelp::resizeEvent(QResizeEvent *)
{
QPixmap pixmap_background=QPixmap(":/res/background_sub2.jpg").scaled(this->size());
QPalette palette(this->palette());
palette.setBrush(QPalette::Background, QBrush(pixmap_background));
this->setPalette(palette);
}
void InstructionHelp::resizeEvent(QResizeEvent *)
{
QPixmap pixmap_background=QPixmap(":/res/background_sub2.jpg").scaled(this->size());
QPalette palette(this->palette());
palette.setBrush(QPalette::Background, QBrush(pixmap_background));
this->setPalette(palette);
}
重载resizeEvent不会被触发,或者有没有其他的实现方法