我正在开发一个程序,在该程序中我创建了几个堆叠的窗口以使用不同的功能。这些窗口是在各自独立的类中制作的。其中一个堆叠的窗口有几个停靠点,我想让它们可以从窗口菜单中切换以显示或隐藏它们。如果它们是主窗口类的一部分,我可以这样做,但文件很大。我的问题是,当我让编辑器类继承主窗口时,我似乎无法显示布局,因为主窗口已经有了布局。即便如此,编译器仍然会为将操作添加到菜单的行抛出错误。是否有人对我如何将它们保存在单独的类中但仍然能够使用主窗口类的私有成员有任何建议。感谢您在高级的帮助!
调用编辑器页面的主窗口的一部分
MainWindow::MainWindow(QWidget *parent)
{
createActions();
createMenu();
createStatusBar();
createDocks();
createMainWidget();
readSettings();
setWindowTitle("Black Ops Bsuiness Group's ERP System - Version 0.0.0.1");
}
void MainWindow::createMainWidget()
{
contentsIconWidget = new QListWidget();
contentsIconWidget->setViewMode(QListView::IconMode);
contentsIconWidget->setIconSize(QSize(70,70));
contentsIconWidget->setMovement(QListView::Static);
contentsIconWidget->setMaximumWidth(75);
contentsIconWidget->setMinimumWidth(75);
contentsIconWidget->setSpacing(10);
contentsIconWidget->setStyleSheet("QListWidget {background-color:#333; color:#0099FF;}");
mainContentPages = new QStackedWidget();
mainContentPages->addWidget(new HomePage);
mainContentPages->addWidget(new AnalyticsPage);
mainContentPages->addWidget(new EditorPage);
mainContentPages->setStyleSheet("QStackedWidget {border:1px solid #888;}");
setCentralWidget(mainContentPages);
createIcons();
contentsIconWidget->setCurrentRow(0);
QHBoxLayout *hMainLayout = new QHBoxLayout();
hMainLayout->addWidget(contentsIconWidget,0);
hMainLayout->addWidget(mainContentPages,0);
hMainLayout->setSpacing(0);
hMainLayout->setMargin(0);
QFrame *mFrame = new QFrame(this);
mFrame->setLayout(hMainLayout);
setCentralWidget(mFrame);
}
存储不同视图状态布局的视图源页面的一部分
EditorPage::EditorPage(QWidget *parent) : QWidget(parent)
{
mdiArea = new QMdiArea;
mdiToolBox = new QToolBox;
QDockWidget *dock = new QDockWidget(tr("SQL Manager"));
//MainWindow::windowMenu->addAction(dock->toggleViewAction());
//MainWindow::windowMenu->addAction(dock->toggleViewAction());
QDockWidget *dock1 = new QDockWidget(tr("SQL Manager"));
QSplitter *splitter = new QSplitter();
splitter->setOrientation(Qt::Vertical);
splitter->addWidget(mdiArea);
splitter->addWidget(dock);
QSplitter *splitter1 = new QSplitter();
splitter1->setOrientation(Qt::Horizontal);
splitter1->addWidget(dock1);
splitter1->addWidget(splitter);
QHBoxLayout *mainLayout = new QHBoxLayout();
mainLayout->addWidget(splitter1);
mainLayout->setSpacing(0);
mainLayout->setMargin(0);
setLayout(mainLayout);
}
视图类头文件的一部分
class EditorPage : public QWidget
{
public:
EditorPage(QWidget *parent = 0);
private:
QMdiArea *mdiArea;
QToolBox *mdiToolBox;
};