0
点赞
收藏
分享

微信扫一扫

38 Containers之QMDIArea

大多数复杂的程序,都使用MDI框架,在Qt designer中可以直接将控件MDI Area拖入使用。 QMdiArea一般使用于主窗口中,用于容纳多个子窗口QMdiSubWindow ,

注意:QMDIArea不能有窗口部件,只能有窗口,但是每个子窗口可以窗口部件

38 Containers之QMDIArea_控件

UI 属性

38 Containers之QMDIArea_子窗口_02

viewMode:窗口模式

tabsClosable:table是否可以删除

tabMovable:table是否可以移动

函数接口介绍

closeAllSubWindows(); //关闭所有子窗口
closeActiveSubWindow();//关闭当前活动窗口
activateNextSubWindow();//激活下一个子窗口
activatePreviousSubWindow();//激活上一个子窗口

实例代码:

Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);

ui->mdiArea->setTabsClosable(true);
ui->mdiArea->setTabsMovable(true);
// ui->mdiArea->setViewMode(QMdiArea::TabbedView);
ui->mdiArea->setFrameShape(QFrame::WinPanel);

QBrush *mdi_b = new QBrush(QColor(255,255,255)); //设置背景为白色
ui->mdiArea->setBackground(*mdi_b);

//创建窗口2
QMdiSubWindow *subWindow1 = new QMdiSubWindow();
QPushButton * button_1 = new QPushButton(QString("按钮1"));
subWindow1->setWidget(button_1);
subWindow1->setAttribute(Qt::WA_DeleteOnClose);
subWindow1->setWindowTitle(QString("窗口1"));//设置窗口名字
ui->mdiArea->addSubWindow(subWindow1);

//创建窗口2
QMdiSubWindow *subWindow2 = new QMdiSubWindow();
QPushButton * button_2 = new QPushButton(QString("按钮2"));
subWindow2->setWidget(button_2);
subWindow2->setAttribute(Qt::WA_DeleteOnClose);
subWindow2->setWindowTitle(QString("窗口1"));//设置窗口名字
ui->mdiArea->addSubWindow(subWindow2);

ui->pushButton->setText(QString("前一个"));
ui->pushButton_2->setText(QString("后一个"));
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(pushButton_Clicked()));
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(pushButton_2_Clicked()));

ui->mdiArea->setViewMode(QMdiArea::TabbedView);//设置为table模式
}

void Widget::pushButton_Clicked()
{
ui->mdiArea->activatePreviousSubWindow();
}

void Widget::pushButton_2_Clicked()
{
ui->mdiArea->activateNextSubWindow();
}

运行结果:

38 Containers之QMDIArea_实例代码_03

 

 

举报

相关推荐

0 条评论