cmakeLists.txt:
cmake_minimum_required(VERSION 3.5) project(Toolkit VERSION "1.0.0.0" LANGUAGES CXX) option(version 1.0.0.0) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets PrintSupport) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets PrintSupport) include(load.cmake) file(GLOB MainWindow ${CMAKE_CURRENT_SOURCE_DIR}/MainWindow/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/MainWindow/*.h ${CMAKE_CURRENT_SOURCE_DIR}/MainWindow/*.ui) include_directories("${QTADVANCEDDOCKING_DIR}/include") set(PROJECT_SOURCES main.cpp ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(TF_SoftwareToolkit MANUAL_FINALIZATION ${PROJECT_SOURCES} ) # Define target properties for Android with Qt 6 as: # set_property(TARGET Toolkit APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # ${CMAKE_CURRENT_SOURCE_DIR}/android) # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation else() if(ANDROID) add_library(Toolkit SHARED ${PROJECT_SOURCES} ) # Define properties for Android with Qt 5 after find_package() calls as: # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") else() add_executable(TF_SoftwareToolkit ${PROJECT_SOURCES} ) endif() endif() target_link_libraries(Toolkit PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::PrintSupport hidapi qtadvanceddocking ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. if(${QT_VERSION} VERSION_LESS 6.1.0) set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.TF_SoftwareToolkit) endif() set_target_properties(Toolkit PROPERTIES ${BUNDLE_ID_OPTION} MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) include(GNUInstallDirs) install(TARGETS Toolkit BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(Toolkit) endif()
头文件:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QShowEvent> #include <DockManager.h> #include <DockAreaWidget.h> #include <DockWidget.h> #include <QSettings> #include "AutoHideDockContainer.h" #include "DockAreaWidget.h" #include "DockAreaTitleBar.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); public: //void saveState(); private: Ui::MainWindow *ui; ads::CDockManager* DockManager; ads::CDockAreaWidget* StatusDockArea; ads::CDockWidget* TimelineDockWidget; ads::CDockAreaWidget* temp; }; #endif // MAINWINDOW_H
cpp文件:
#include "mainwindow.h" #include "./ui_mainwindow.h" using namespace ads; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , m_deviceinfowidget(new DeviceInfoWidget) , m_elasticWaveformWidget(new ElasticWaveformWidget) , m_forceWaveformWidget(new ForceWaveformWidget) , m_gestureParameterWidget(new GestureParameterWidget) , m_logWidget(new LogWidget) { ui->setupUi(this); QString version = QCoreApplication::applicationVersion(); QString verInfo = " 钛方标准化软件工具 - 版本:V" + QString("1.0.0.0") + QString((version.right(1) != "0") ? " debug" : " release"); this->setWindowTitle(verInfo); CDockManager::setConfigFlag(CDockManager::OpaqueSplitterResize, true); CDockManager::setConfigFlag(CDockManager::XmlCompressionEnabled, false); CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true); CDockManager::setAutoHideConfigFlags(CDockManager::DefaultAutoHideConfig); DockManager = new CDockManager(this); //0窗口 CDockWidget* 0CDockWidget= new CDockWidget("产品信息"); 0CDockWidget->setWidget(0widget); auto* 0DockWidgetArea = DockManager->addDockWidget(DockWidgetArea::OuterDockAreas,0CDockWidget); //deviceInfoDockWidgetArea->setMaximumWidth(250); ui->menuView->addAction(deviceInfoCDockWidget->toggleViewAction()); // 1窗口 CDockWidget* 1CDockWidget= new CDockWidget("日志"); 1CDockWidget->setWidget(1Widget); auto* 1DockWidgetArea = DockManager->addDockWidget(DockWidgetArea::BottomDockWidgetArea,1CDockWidget,1DockWidgetArea); //logDockWidgetArea->setMaximumWidth(250); ui->menuView->addAction(1CDockWidget->toggleViewAction()); // 2窗口 CDockWidget* 2mCDockWidget= new CDockWidget(1窗口"); 2CDockWidget->setWidget(2Widget); auto* 2DockWidgetArea = DockManager->addDockWidget(DockWidgetArea::RightDockWidgetArea,2CDockWidget); ui->menuView->addAction(2CDockWidget->toggleViewAction()); // 3窗口 CDockWidget* 3DockWidget= new CDockWidget("2窗口"); 3CDockWidget->setWidget(3Widget); DockManager->addDockWidget(DockWidgetArea::BottomDockWidgetArea,3CDockWidget,2DockWidgetArea); ui->menuView->addAction(3CDockWidget->toggleViewAction()); // 4窗口 CDockWidget* 4CDockWidget= new CDockWidget("3窗口"); 4CDockWidget->setWidget(m4Widget); DockManager->addDockWidget(DockWidgetArea::RightDockWidgetArea,4CDockWidget); ui->menuView->addAction(4CDockWidget->toggleViewAction()); QSettings Settings("Settings.ini", QSettings::IniFormat); this->restoreGeometry(Settings.value("mainWindow/Geometry").toByteArray()); this->restoreState(Settings.value("mainWindow/State").toByteArray()); DockManager->restoreState(Settings.value("mainWindow/DockingState").toByteArray()); } MainWindow::~MainWindow() { delete ui; QSettings Settings("Settings.ini", QSettings::IniFormat); Settings.setValue("mainWindow/Geometry", this->saveGeometry()); Settings.setValue("mainWindow/State", this->saveState()); Settings.setValue("mainWindow/DockingState", DockManager->saveState()); }
标签:窗口,qt,CDockWidget,VERSION,停靠,CMAKE,new,include,MainWindow From: https://www.cnblogs.com/RedWetPlace/p/18175712