1、使用
直接拖动
然后选择添加子窗口就可以了
但是正常情况下子窗口初始是最小化显示的,需要在代码中添加
QMdiSubWindow *newwin = new QMdiSubWindow(this);
newwin->setWindowTitle("test");
newwin->setAttribute(Qt::WA_DeleteOnClose);
newwin->resize(200,200);
ui->mdiArea->addSubWindow(newwin);
newwin->show();
效果:
但是有时候我们想将自己创建的对话框当做子窗口
addcombo *dlg = new addcombo(this);
dlg->setWindowTitle("test");
dlg->setAttribute(Qt::WA_DeleteOnClose);
ui->mdiArea->addSubWindow(dlg)->resize(200,200);
dlg->show();
效果:
去掉子对话框上面的按钮
Dialog1 *dlg = new Dialog1(this);
//ui->mdiArea->addSubWindow(dlg)->setFixedSize(200,200);//设置为固定大小
ui->mdiArea->addSubWindow(dlg, Qt::WindowSystemMenuHint)->setFixedSize(200,200);//设置为固定大小,并且去掉最小化和最大化按钮
//ui->mdiArea->addSubWindow(dlg, Qt::CustomizeWindowHint)->setFixedSize(200,200);//设置固定大小,并去掉最小化最大化和关闭按钮
dlg->show();
创建的子窗口摆放
Dialog1 *dlg = new Dialog1(this);
static int a = 0;
dlg->setWindowTitle(QString::number(a));
a++;
ui->mdiArea->addSubWindow(dlg, Qt::WindowSystemMenuHint)->setFixedSize(200,200);
dlg->show();
ui->mdiArea->cascadeSubWindows();//以层叠模式排列所有子窗口。
获取里面的子窗口关闭的信号
connect(dlg,&Dialog1::destroyed,[=]()
{
//填写代码,修改状态
});
2、设置背景图片
QPixmap bgPix(":/img/32.png");
ui->mdiArea->setBackground(QBrush(bgPix));
中间
ui->mdiArea->setBackground(QBrush(Qt::NoBrush));
ui->mdiArea->setStyleSheet("QMdiArea{"
" background-image: url(:/img/32.png);"
" background-repeat: no-repeat;"//设置图片重复类型
" background-position: center;"//居中
" background-color: rgba(0, 0, 0, 0);"//背景透明
" }");