搜索论坛
显示结果为标签'qdockwidget'。
找到1个结果
-
首先看效果图 项目结构: vs.h: #ifndef VS_H #define VS_H #include <QMainWindow> #include <QAction> #include <QLabel> #include <QResizeEvent> #include <QToolBar> QT_BEGIN_NAMESPACE namespace Ui { class VS; } QT_END_NAMESPACE class VS : public QMainWindow { Q_OBJECT public: VS(QWidget *parent = nullptr); ~VS(); void initStatusBar(); void initActionBar(); void initDock(); void resizeEvent(QResizeEvent *) override; private: Ui::VS *ui; QWidget* statusBar; //状态栏 QWidget* actionBar; //动作栏 QWidget* body; QWidget* widget_left; QWidget* widget_right; QWidget* wapper; QWidget* output; QWidget* errors; QDockWidget *dockTop; QDockWidget *dockLeft; QDockWidget *dockRight; QDockWidget *dockMain; QDockWidget *dockOutput; QDockWidget *dockErrors; QList<QDockWidget*> dockList; QList<int> widthList; QList<QDockWidget*> dockList2; QList<int> heightList; private slots: void setActiveDock(bool); }; #endif // VS_H vs.cpp: #include "vs.h" #include "ui_vs.h" #include <QDockWidget> #include <QDebug> VS::VS(QWidget *parent) : QMainWindow(parent) , ui(new Ui::VS) { ui->setupUi(this); this->setMinimumSize(1200,800); this->setStyleSheet("font-size:14px;font-family: \"Microsoft Yahei\";"); //删除默认窗体 QWidget* centralWidget = takeCentralWidget(); if(centralWidget) { delete centralWidget; } this->initActionBar(); this->initStatusBar(); //允许嵌套dock setDockNestingEnabled(true); body = new QWidget(this); body->setObjectName("body"); body->setStyleSheet("#body{background:#EEEEF2;}"); body->resize(this->width(),this->height() - ui->menubar->height() - statusBar->height() - actionBar->height()); body->move(0,ui->menubar->height() + actionBar->height()); this->initDock(); } VS::~VS() { delete ui; } //初始化状态栏 void VS::initStatusBar() { statusBar = new QWidget(this); statusBar->setObjectName("statusBar"); statusBar->setStyleSheet("#statusBar{background:#2b579a;color:#fff;}"); statusBar->resize(this->width(),26); statusBar->move(0,this->height() - 26); QLabel* label_copy = new QLabel(statusBar); label_copy->setObjectName("label_copy"); label_copy->setStyleSheet("#label_copy{color:#fff;background:#2b579a;}"); label_copy->setText("版权所有"); label_copy->show(); } //初始化动作 void VS::initActionBar() { actionBar = new QWidget(this); actionBar->setObjectName("actionBar"); actionBar->setStyleSheet("#actionBar{background:#EEEEF2;}"); actionBar->resize(this->width(),26); actionBar->setFixedHeight(26); actionBar->setMaximumHeight(26); actionBar->move(0,ui->menubar->height()); QLabel* ico_left = new QLabel(actionBar); ico_left->setStyleSheet("background:transparent;"); ico_left->setPixmap(QPixmap::fromImage(QImage(":/Resources/icon/SelectAll_32x32.png"))); ico_left->resize(18,18); ico_left->setScaledContents(true); ico_left->move(5,4); ico_left->show(); QLabel* ico_right = new QLabel(actionBar); ico_right->setStyleSheet("background:transparent;"); ico_right->setPixmap(QPixmap::fromImage(QImage(":/Resources/icon/InsertSheetRows_32x32.png"))); ico_right->resize(18,18); ico_right->setScaledContents(true); ico_right->move(ico_left->x() + ico_left->width() + 5,4); ico_right->show(); QLabel* ico_resume = new QLabel(actionBar); ico_resume->setStyleSheet("background:transparent;"); ico_resume->setPixmap(QPixmap::fromImage(QImage(":/Resources/icon/InsertTable_32x32.png"))); ico_resume->resize(18,18); ico_resume->setScaledContents(true); ico_resume->move(ico_right->x() + ico_right->width() + 5,4); ico_resume->show(); QLabel* ico_save = new QLabel(actionBar); ico_save->setStyleSheet("background:transparent;"); ico_save->setPixmap(QPixmap::fromImage(QImage(":/Resources/icon/OptionsPivotTable_32x32.png"))); ico_save->resize(18,18); ico_save->setScaledContents(true); ico_save->move(ico_resume->x() + ico_resume->width() + 5,4); ico_save->show(); } void VS::initDock() { widget_left = new QWidget(body); widget_left->setObjectName("widget_left"); widget_left->setStyleSheet("#widget_left{background:#F5F5F5;border:1px solid #DDDEE6;}"); widget_right = new QWidget(body); widget_right->setObjectName("widget_right"); widget_right->setStyleSheet("#widget_right{background:#F5F5F5;border:1px solid #DDDEE6;}"); //widget_right->setMinimumWidth(40); //widget_right->setMaximumWidth(240); wapper = new QWidget(body); wapper->setObjectName("wapper"); wapper->setStyleSheet("#wapper{background:#F5F5F5;border:1px solid #DDDEE6;}"); output = new QWidget(body); output->setObjectName("output"); output->setStyleSheet("#output{background:#fff;border:1px solid #DDDEE6;}"); output->show(); errors = new QWidget(body); errors->setObjectName("errors"); errors->setStyleSheet("#errors{background:#fff;border:1px solid #DDDEE6;}"); errors->show(); dockTop = new QDockWidget(tr("Dock top"), this); dockTop->setWidget(actionBar); dockTop->setAllowedAreas(Qt::TopDockWidgetArea); //隐藏头部 QWidget* lTitleBar = dockTop->titleBarWidget(); QWidget* lEmptyWidget = new QWidget(); dockTop->setTitleBarWidget(lEmptyWidget); delete lTitleBar; addDockWidget(Qt::TopDockWidgetArea, dockTop); dockLeft = new QDockWidget("工具栏", this); dockLeft->setObjectName("dockLeft"); dockLeft->setWidget(widget_left); addDockWidget(Qt::LeftDockWidgetArea, dockLeft); dockLeft->setStyleSheet("#dockLeft::title{background:#EEEEF2;border:1px solid #DDDEE6;}"); dockRight = new QDockWidget("资源管理器", this); dockRight->setWidget(widget_right); dockRight->setObjectName("dockRight"); dockRight->setStyleSheet("#dockRight::title{background:#EEEEF2;border:1px solid #DDDEE6;}"); dockMain = new QDockWidget(tr("Dock wapper"), this); dockMain->setWidget(wapper); QWidget* dockMainTitleBar = dockMain->titleBarWidget(); QWidget* _dockMainTitleBar = new QWidget(); dockMain->setTitleBarWidget(_dockMainTitleBar); delete dockMainTitleBar; dockOutput = new QDockWidget("输出", this); dockOutput->setWidget(output); dockOutput->setObjectName("dockOutput"); dockOutput->setStyleSheet("#dockOutput::title{background:#2b579a;}"); dockErrors = new QDockWidget("错误列表", this); dockErrors->setWidget(errors); dockErrors->setObjectName("dockErrors"); dockErrors->setStyleSheet("#dockErrors::title{background:#2b579a;}"); splitDockWidget(dockTop,dockLeft,Qt::Vertical); splitDockWidget(dockLeft,dockMain,Qt::Horizontal); splitDockWidget(dockMain,dockRight,Qt::Horizontal); splitDockWidget(dockMain,dockOutput,Qt::Vertical); tabifyDockWidget(dockOutput,dockErrors); dockOutput->raise(); dockList << dockLeft << dockMain << dockRight; widthList << static_cast<int>(this->geometry().width() * 0.15) << static_cast<int>(this->geometry().width() * 0.6) << static_cast<int>(this->geometry().width() * 0.25); dockList2 << dockMain << dockOutput; heightList << static_cast<int>(body->height() * 0.6) << static_cast<int>(body->height() * 0.4); this->resizeDocks(dockList, widthList, Qt::Horizontal); this->resizeDocks(dockList2, heightList, Qt::Vertical); connect(dockOutput,&QDockWidget::visibilityChanged,this,[=](bool v){ if(v) { dockOutput->raise(); } }); connect(dockErrors,&QDockWidget::visibilityChanged,this,[=](bool v){ if(v) { dockErrors->raise(); } }); } void VS::resizeEvent(QResizeEvent *) { actionBar->resize(this->width(),26); statusBar->resize(this->width(),26); statusBar->move(0,this->height() - 26); body->resize(this->width(),this->height() - ui->menubar->height() - statusBar->height() - actionBar->height()); body->move(0,ui->menubar->height() + actionBar->height()); } void VS::setActiveDock(bool) { }