当前位置: 代码迷 >> QT开发 >> 主界面怎么调用其他界面
  详细解决方案

主界面怎么调用其他界面

热度:48   发布时间:2016-04-25 04:38:28.0
主界面如何调用其他界面?
如题。
主界面分成三个部分,将原来每部分的内容分别写到三个ui文件中去,如何在主界面中调用显示这三个ui文件,使其跟不分开时完全一样?

谢谢!

------解决方案--------------------


建立3个派生QWidget , 分别继承 3 个ui

用layout布局出来 显示


------解决方案--------------------
这个和你初始化主界面的时候是差不多的 
先包含.ui文件的头文件
初始化一个和ui文件中控件类型一样的控件
给这个控件setupUi(你ui中的控件名)

具体的你可以在 Qt助手索引里搜一下 Using a Designer UI File in Your Application
------解决方案--------------------
用DockWidget,setupUi(你的ui),再add to mainwindow
或者用个area控件,再添加到mainwindow的layout中也可以啊,如果要界面好看的话还是建议用dockWidget,隐藏/显示的部分实现起来简单些
 void MainWindow::createDockWindows()
 {
QDockWidget *dock = new QDockWidget(tr("Customers"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
customerList = new QListWidget(dock);
customerList->addItems(QStringList()
<< "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
<< "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
dock->setWidget(customerList);
addDockWidget(Qt::RightDockWidgetArea, dock);
viewMenu->addAction(dock->toggleViewAction());

dock = new QDockWidget(tr("Paragraphs"), this);
paragraphsList = new QListWidget(dock);
paragraphsList->addItems(QStringList()
<< "Thank you for your payment which we have received today."
<< "Your order has been dispatched and should be with you "
"within 28 days."
<< "You made an overpayment (more than $5). Do you wish to "
"buy more items, or should we return the excess to you?");
dock->setWidget(paragraphsList);
addDockWidget(Qt::RightDockWidgetArea, dock);
viewMenu->addAction(dock->toggleViewAction());

connect(customerList, SIGNAL(currentTextChanged(QString)),
this, SLOT(insertCustomer(QString)));
connect(paragraphsList, SIGNAL(currentTextChanged(QString)),
this, SLOT(addParagraph(QString)));
 }
------解决方案--------------------
这问题问的,只要你拥有那三个ui的指针,你想在哪里显示就在哪里显示,想怎么显示就怎么显示
  相关解决方案