1.界面设计

this->resize(QSize(1600, 800));
proModel = new QStandardItemModel(this);

//菜单栏设置
pMenubar = new QMenuBar;
pMenubar->setStyleSheet("background-color:#B0C4DE");
QMenu *pMenuStart = pMenubar->addMenu(QStringLiteral("开始"));
QMenu *pMenuOption = pMenubar->addMenu(QStringLiteral("选项"));
QMenu *pMenuEdit = pMenubar->addMenu(QStringLiteral("编辑"));
QMenu *pMenuTools = pMenubar->addMenu(QStringLiteral("工具"));
QMenu *pMenuView = pMenubar->addMenu(QStringLiteral("视图"));
QMenu *pMenuAbout = pMenubar->addMenu(QStringLiteral("关于"));

//视图菜单
pViewProject = pMenuView->addAction(QStringLiteral("项目"));
pViewMaintab = pMenuView->addAction(QStringLiteral("主页"));
pViewLog = pMenuView->addAction(QStringLiteral("日志"));
pViewDevice = pMenuView->addAction(QStringLiteral("设备管理"));
pViewToolsbar = pMenuView->addAction(QStringLiteral("工具栏"));
pViewDevice->setCheckable(true);
pViewProject->setCheckable(true);
pViewMaintab->setCheckable(true);
pViewLog->setCheckable(true);
pViewToolsbar->setCheckable(true);
pViewDevice->setChecked(true);
pViewLog->setChecked(true);
pViewMaintab->setChecked(true);
pViewProject->setChecked(true);
pViewToolsbar->setChecked(true);
connect(pViewDevice, &QAction::changed, this, &MainWindow::on_view_device_changed);
connect(pViewProject, &QAction::changed, this, &MainWindow::on_view_project_changed);
connect(pViewLog, &QAction::changed, this, &MainWindow::on_view_log_changed);
connect(pViewMaintab, &QAction::changed, this, &MainWindow::on_view_maintab_changed);
connect(pViewToolsbar, &QAction::changed, this, &MainWindow::on_view_toolsbar_changed);

QAction *pNew = pMenuStart->addAction(QIcon(":/images/add-one.png"), tr("新建项目"));
connect(pNew, &QAction::triggered, this, &MainWindow::on_new_project_clicked);
pMenuStart->addSeparator();
QAction *pClose = pMenuStart->addAction(QIcon(":/images/close.png"), tr("关闭项目"));
connect(pClose, &QAction::triggered, this, &MainWindow::on_close_project_clicked);

this->setMenuBar(pMenubar);

//工具栏设置
pToolbar = this->addToolBar(QStringLiteral("toolBar"));
pToolbar->setStyleSheet("background-color:#F0F8FF");
//pToolbar->addAction(pNew);
QList<QAction *> actions;
actions.append(pNew);
actions.append(pClose);
pToolbar->addActions(actions);

//项目导航栏
pGroupBox_project = new QGroupBox(tr("项目导航"));
pGroupBox_project->setAlignment(Qt::AlignLeft);
pListView_project = new QListView;
pListView_project->setEditTriggers(QAbstractItemView::NoEditTriggers);
connect(pListView_project, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_prolist_double_clicked(QModelIndex)));
pTabWidget_project = new QTabWidget;
pTabWidget_project->setStyleSheet("background-color:#F8F8FF");
QSplitter *vSplitter_project = new QSplitter(Qt::Vertical);
vSplitter_project->addWidget(pListView_project);
vSplitter_project->addWidget(pTabWidget_project);
vSplitter_project->setStretchFactor(1, 40);
vSplitter_project->setStretchFactor(2, 60);
QGridLayout *proLayout = new QGridLayout;
proLayout->addWidget(vSplitter_project);
pGroupBox_project->setLayout(proLayout);

//主窗口
QWidget *pWidget = new QWidget;
pMainTabwidget = new QTabWidget;
pMainTabwidget->setMovable(true); //可移动
//pMainTabwidget->setTabBarAutoHide(true); //标签个数为1时自动隐藏
pMainTabwidget->setTabPosition(QTabWidget::North);
pMainTabwidget->setTabShape(QTabWidget::Triangular);
pMainTabwidget->setTabsClosable(true);
pMainTabwidget->setUsesScrollButtons(true);
//pMainTabwidget->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint);
pTableView_project = new QTableView;
proInfoModel = new QStandardItemModel();
pTableView_project->setModel(proInfoModel);
#if 0
pTableView_project->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
#else
pTableView_project->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
pTableView_project->horizontalHeader()->setStretchLastSection(true);
#endif
pTableView_project->horizontalHeader()->setStyleSheet("QHeaderView::section {background-color:#B0C4DE}");
proInfoModel->setHorizontalHeaderItem(0, new QStandardItem(QObject::tr("属性")));
proInfoModel->setHorizontalHeaderItem(1, new QStandardItem(QObject::tr("属性值")));
QStandardItem *item;
proInfoModel->setItem(0, 0, new QStandardItem(tr("项目名称")));
proInfoModel->setItem(1, 0, new QStandardItem(tr("项目描述")));
item = new QStandardItem(tr("设备型号"));
item->setEditable(false);
proInfoModel->setItem(2, 0, item);
item = new QStandardItem(tr("创建时间"));
item->setEditable(false);
proInfoModel->setItem(3, 0, item);
item = new QStandardItem(tr("修改时间"));
item->setEditable(false);
proInfoModel->setItem(4, 0, item);
item = new QStandardItem(tr("存储路径"));
item->setEditable(false);
proInfoModel->setItem(5, 0, item);
pTableView_project->setSelectionBehavior(QAbstractItemView::SelectRows);
QDialogButtonBox *pButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
pButtonBox->buttons().at(0)->setText(tr("修改"));
pButtonBox->buttons().at(1)->setText(tr("取消"));
QVBoxLayout *MainVlayout = new QVBoxLayout;
MainVlayout->addWidget(pTableView_project);
MainVlayout->addWidget(pButtonBox);
pWidget->setLayout(MainVlayout);
pMainTabwidget->addTab(pWidget, "主页");

//日志窗口
pSourthTable = new QTabWidget;
QTextBrowser *logpage = new QTextBrowser;
logpage->setText("welcome");
pSourthTable->addTab(logpage, "系统日志");

//设备管理窗口
pGroupBox_device = new QGroupBox(tr("设备管理"));
pGroupBox_device->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint);
pGroupBox_project->setAlignment(Qt::AlignLeft);
pTabWidget_devices = new QTabWidget(this);
QGridLayout *devlayout = new QGridLayout;
devlayout->addWidget(pTabWidget_devices);
pGroupBox_device->setLayout(devlayout);
SgwDevice *pDevice_manager = new SgwDevice;
pTabWidget_devices->addTab(pDevice_manager->pConnectWidget, (tr("连接")));
//pTabWidget_devices->show();

//整体布局
QGridLayout *mainLayout = new QGridLayout;
QSplitter * hSplitter = new QSplitter(Qt::Horizontal);
QSplitter *vSplitter = new QSplitter(Qt::Vertical);
QSplitter *hSplitter_right = new QSplitter(Qt::Horizontal);
hSplitter_right->setHandleWidth(5);
hSplitter->setHandleWidth(5);
vSplitter->setHandleWidth(5);
hSplitter->setChildrenCollapsible(false);
vSplitter->setChildrenCollapsible(false);
hSplitter_right->setChildrenCollapsible(false);

hSplitter_right->addWidget(pMainTabwidget);
hSplitter_right->addWidget(pGroupBox_device);
hSplitter_right->setStretchFactor(0, 65);
hSplitter_right->setStretchFactor(1, 35);

vSplitter->addWidget(hSplitter_right);
vSplitter->addWidget(pSourthTable);
vSplitter->setStretchFactor(0, 80);
vSplitter->setStretchFactor(1, 20);

hSplitter->addWidget(pGroupBox_project);
hSplitter->addWidget(vSplitter);
hSplitter->setStretchFactor(0, 20);
hSplitter->setStretchFactor(1, 80);

#if 0
int width = this->frameGeometry().width();
hSplitter->setSizes(QList<int>()<<1/10*width<<6/10*width<<3/10*width);
#endif
mainLayout->addWidget(hSplitter);
mainWidget = new QWidget(this);
mainWidget->setLayout(mainLayout);
this->setCentralWidget(mainWidget);
setWindowTitle(tr("SGW EDITER V0.0.1"));
this->setWindowIcon(QIcon(":/images/boxing-one.png"));

2.界面展示

 QT代码设计界面_界面