关于Qt开发UI框架Qt Advanced Docking System测试

案例使用QWidget窗体进行测试,大部分问题基本解决,也确实是个非常不错的布局库,官方案例使用QMainWidget可以实现边缘区域隐藏非常适合作为参数设置,但在QWidget内使用有问题,不知道怎么原因,测试图片如下所示,标题栏样式微调

我感觉有几个优点很好用

1、任意布局停靠

2、可自动保存、还原布局

3、可绑定QAction控件实现显示和隐藏

下载链接https://download.csdn.net/download/lidengfeng0ff/92178691?spm=1001.2014.3001.5503

复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QSettings>
#include "DockManager.h"
#include "form.h"

namespace Ui {
class Widget;
}

using namespace ads;

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();
protected:
    void showEvent(QShowEvent *event);

private:
    Ui::Widget *ui;
    ads::CDockManager* m_DockManager;
    ads::CDockWidget* DockWidget1;
    ads::CDockWidget* DockWidget2;
    ads::CDockWidget* DockWidget3;
    Form form1;
    Form form2;
    Form form3;
private:
    void saveDockLayout() {
        QSettings Settings("Settings.ini", QSettings::IniFormat);
        Settings.setValue("mainWindow/DockingState", m_DockManager->saveState());
    }

    void restoreDockLayout() {
        QSettings Settings("Settings.ini", QSettings::IniFormat);
        m_DockManager->restoreState(Settings.value("mainWindow/DockingState").toByteArray());
    }

};

#endif // WIDGET_H

#include "widget.h"
#include "ui_widget.h"

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

    //新建管理器
    m_DockManager = new ads::CDockManager();
    ui->verticalLayout->addWidget(m_DockManager);


    //添加子窗口
    DockWidget1 = m_DockManager->createDockWidget(QString("图像"));
    DockWidget1->setWidget(&form1);
    //设置子窗口禁止关闭
    DockWidget1->setFeatures(ads::CDockWidget::DockWidgetDeleteOnClose |
                     ads::CDockWidget::DockWidgetMovable);
    //放置子窗口
    m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget1);
    QAction* showAction1 = DockWidget1->toggleViewAction();
    this->setContextMenuPolicy(Qt::ActionsContextMenu);
    this->addAction(showAction1);

    DockWidget2 = m_DockManager->createDockWidget(QString("曲线1"));
    DockWidget2->setWidget(&form2);
    DockWidget2->setAutoHide(true);
    //设置子窗口禁止关闭
    DockWidget2->setFeatures(ads::CDockWidget::DockWidgetClosable |
                     ads::CDockWidget::DockWidgetMovable);
    m_DockManager->addDockWidget(ads::RightDockWidgetArea, DockWidget2);
    QAction* showAction2 = DockWidget2->toggleViewAction();
    this->addAction(showAction2);


    DockWidget3 = m_DockManager->createDockWidget(QString("曲线2"));
    DockWidget3->setWidget(&form3);
    //设置子窗口禁止关闭
    DockWidget3->setFeatures(ads::CDockWidget::DockWidgetClosable |
                     ads::CDockWidget::DockWidgetMovable|ads::CDockWidget::DockWidgetPinnable);
    m_DockManager->addDockWidget(ads::RightAutoHideArea, DockWidget3);
    QAction* showAction3 = DockWidget3->toggleViewAction();
    this->addAction(showAction3);

    QFile StyleSheetFile("visual_studio_light.css");
    StyleSheetFile.open(QIODevice::ReadOnly);
    QTextStream StyleSheetStream(&StyleSheetFile);
    auto Stylesheet = StyleSheetStream.readAll();
    m_DockManager->setStyleSheet(Stylesheet);
}

Widget::~Widget()
{
    saveDockLayout();
    delete ui;
}

void Widget::showEvent(QShowEvent *event)
{
    restoreDockLayout();
}
相关推荐
blasit1 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
郑州光合科技余经理6 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1236 天前
matlab画图工具
开发语言·matlab
dustcell.6 天前
haproxy七层代理
java·开发语言·前端
norlan_jame6 天前
C-PHY与D-PHY差异
c语言·开发语言
多恩Stone6 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
修炼前端秘籍的小帅6 天前
Stitch——Google热门的免费AI UI设计工具
前端·人工智能·ui
QQ4022054966 天前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
遥遥江上月6 天前
Node.js + Stagehand + Python 部署
开发语言·python·node.js
王码码20356 天前
Flutter for OpenHarmony:socket_io_client 实时通信的事实标准(Node.js 后端的最佳拍档) 深度解析与鸿蒙适配指南
android·flutter·ui·华为·node.js·harmonyos