|
| void | setWindowTitle (const QString &windowTitle) |
| | 设置对话标题栏内容
|
| |
| void | setProductIcon (const QIcon &icon) |
| | 设置展示的 icon 图标.
|
| |
| void | setProductName (const QString &productName) |
| | 设置对话框显示的应用名称
|
| |
| void | setVersion (const QString &version) |
| | 设置指定的 version 版本信息
|
| |
| void | setDescription (const QString &description) |
| | 此函数用于设置指定的 description 描述信息.
|
| |
|
void | setCompanyLogo (const QPixmap &companyLogo) |
| | 此函数用于设置指定的 companyLogo 组织标志
|
| |
| void | setWebsiteName (const QString &websiteName) |
| | 设置指向的网站名
|
| |
| void | setWebsiteLink (const QString &websiteLink) |
| | 设置指定的网站连接
|
| |
|
void | setAcknowledgementVisible (bool visible) |
| | 设置鸣谢是否可见
|
| |
| void | setLicense (const QString &license) |
| | 设置指定的license许可证
|
| |
| int | addButton (const QString &text, bool isDefault=false, ButtonType type=ButtonNormal) |
| | 向对话框添加按钮
|
| |
| int | addButtons (const QStringList &text) |
| | 向对话框添加按钮
|
| |
| void | insertButton (int index, const QString &text, bool isDefault=false, ButtonType type=ButtonNormal) |
| | 向对话框插入按钮
|
| |
| void | insertButton (int index, QAbstractButton *button, bool isDefault=false) |
| | 向对话框插入按钮
|
| |
| void | insertButtons (int index, const QStringList &text) |
| | 向对话框插入按钮
|
| |
| void | removeButton (int index) |
| | 从对话框移除按钮
|
| |
| void | removeButton (QAbstractButton *button) |
| | 从对话框移除按钮
|
| |
| void | removeButtonByText (const QString &text) |
| | 从对话框移除按钮
|
| |
|
void | clearButtons () |
| | 清除所有按钮
|
| |
| bool | setDefaultButton (int index) |
| | 设置默认按钮
|
| |
| bool | setDefaultButton (const QString &str) |
| | 设置默认按钮
|
| |
| void | setDefaultButton (QAbstractButton *button) |
| | 设置默认按钮
|
| |
| void | addContent (QWidget *widget, Qt::Alignment alignment={}) |
| | 添加控件到对话框内容布局.
|
| |
| void | insertContent (int index, QWidget *widget, Qt::Alignment alignment={}) |
| | 在对话框内容布局指定位置插入控件.
|
| |
| void | removeContent (QWidget *widget, bool isDelete=true) |
| | 从对话框内容布局中移除指定控件
|
| |
| void | clearContents (bool isDelete=true) |
| | 清空对话框内容布局中的所有内容.
|
| |
| void | setSpacing (int spacing) |
| | 设置对话框内容间隔
|
| |
| void | addSpacing (int spacing) |
| | 追加对话框内容间隔.
|
| |
| void | insertSpacing (int index, int spacing) |
| | 插入对话框内容间隔
|
| |
| void | clearSpacing () |
| | 清除内容间隔
|
| |
| void | setButtonText (int index, const QString &text) |
| | 设置按钮文字
|
| |
| void | setButtonIcon (int index, const QIcon &icon) |
| | 设置按钮图标
|
| |
| void | setTitle (const QString &title) |
| | 设置对话框标题
|
| |
| void | setWordWrapTitle (bool wordWrap) |
| | 设定标题Label内容是否可截断换行
|
| |
| void | setMessage (const QString &message) |
| | 设置对话框消息内容
|
| |
|
void | setWordWrapMessage (bool wordWrap) |
| | 设置对话框消息内容
|
| |
| void | setIcon (const QIcon &icon) |
| | 设置对话框图标
|
| |
| void | setTextFormat (Qt::TextFormat textFormat) |
| | 设置文字格式
|
| |
| void | setOnButtonClickedClose (bool onButtonClickedClose) |
| | 设置是否在点击按钮后关闭对话框
|
| |
|
void | setCloseButtonVisible (bool closeButtonVisible) |
| | 设置关闭按钮的可见性
|
| |
| int | exec () Q_DECL_OVERRIDE |
| | 以模态框形式显示当前对话框
|
| |
|
void | moveToCenter () |
| | 将对话框移动至屏幕中央或其父控件的中央
|
| |
|
void | moveToTopRight () |
| | 将对话框移动至屏幕右上角或其父控件的右上角
|
| |
|
void | moveToCenterByRect (const QRect &rect) |
| | 移动对话框到给定rect区域的中央。rect是移动对话框要参照的QRect区域
|
| |
|
void | moveToTopRightByRect (const QRect &rect) |
| | 移动对话框到给定rect区域的右上角。rect是移动所需要参照的QRect位置。
|
| |
| void | setDisplayPosition (DisplayPosition displayPosition) |
| | 设置对话框显示位置
|
| |
|
|
void | keyPressEvent (QKeyEvent *event) Q_DECL_OVERRIDE |
| |
|
void | showEvent (QShowEvent *event) Q_DECL_OVERRIDE |
| |
|
| DDialog (DDialogPrivate &dd, QWidget *parent=0) |
| |
| void | showEvent (QShowEvent *event) Q_DECL_OVERRIDE |
| |
| void | hideEvent (QHideEvent *event) Q_DECL_OVERRIDE |
| |
|
void | closeEvent (QCloseEvent *event) override |
| |
|
void | childEvent (QChildEvent *event) Q_DECL_OVERRIDE |
| |
|
void | resizeEvent (QResizeEvent *event) override |
| |
|
void | keyPressEvent (QKeyEvent *event) override |
| |
|
bool | eventFilter (QObject *watched, QEvent *event) override |
| |
|
void | changeEvent (QEvent *event) override |
| |
| void | mouseMoveEvent (QMouseEvent *event) Q_DECL_OVERRIDE |
| | 对话框的鼠标移动事件
|
| |
| void | mousePressEvent (QMouseEvent *event) Q_DECL_OVERRIDE |
| | 对话框的鼠标点击事件
|
| |
| void | mouseReleaseEvent (QMouseEvent *event) Q_DECL_OVERRIDE |
| | 对话框的鼠标释放事件
|
| |
| void | resizeEvent (QResizeEvent *event) Q_DECL_OVERRIDE |
| | 窗口大小改变事件
|
| |
| void | showEvent (QShowEvent *event) override |
| | 窗口显示事件,如果收到过鼠标移动事件不再使用自动布局
|
| |
|
| DAbstractDialog (DAbstractDialogPrivate &dd, QWidget *parent=nullptr) |
| |
DAboutDialog 类提供了应用程序的关于对话框, 规范所有 deepin 应用关于窗口设计规范, 符合 deepin 风格
概述
DAboutDialog 类提供了应用程序的关于对话框
项目目录结构在同一目录下
CMakeLists.txt
cmake_minimum_required(VERSION 3.1.0) # 指定cmake最低版本
project(example1 VERSION 1.0.0 LANGUAGES CXX) # 指定项目名称, 版本, 语言 cxx就是c++
set(CMAKE_CXX_STANDARD 11) # 指定c++标准
set(CMAKE_CXX_STANDARD_REQUIRED ON) # 指定c++标准要求,至少为11以上
set(target example1) # 指定目标名称
set(CMAKE_AUTOMOC ON) # support qt moc # 支持qt moc
set(CMAKE_AUTORCC ON) # support qt resource file # 支持qt资源文件
set(CMAKE_AUTOUIC ON) # support qt ui file # 支持qt ui文件(非必须)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # support clangd 支持 clangd
if (CMAKE_VERSION VERSION_LESS "3.7.0") # 如果cmake版本小于3.7.0
set(CMAKE_INCLUDE_CURRENT_DIR ON) # 设置包含当前目录
endif()
find_package(Qt5 COMPONENTS Widgets REQUIRED) # 寻找Qt5组件Widgets
find_package(Qt5 COMPONENTS Gui REQUIRED) # 寻找Qt5组件Gui
find_package(Dtk COMPONENTS Widget REQUIRED) # 寻找Dtk组件Widget
find_package(Dtk COMPONENTS Core REQUIRED) # 寻找Dtk组件Core
find_package(Dtk COMPONENTS Gui) # 寻找Dtk组件Gui
add_executable(example1 # 添加可执行文件
main.cpp
)
target_link_libraries(example1 PRIVATE
Qt5::Widgets
Qt5::Gui
dtkgui
dtkcore
dtkwidget
) # 链接库
main.cpp
#include <DAboutDialog>
#include <DApplication>
DWIDGET_USE_NAMESPACE
int main(int argc, char *argv[]) {
app.setProductName("Dtk example");
app.setOrganizationName("deepin");
about.show();
}
这是一个最简单的例子,运行结果如下
example
但是这个例子并不是我们实际上使用的样子,在我们实际上的使用过程中,我们需要添加一些信息,比如我们的logo,我们的版本号,我们的版权信息等等,这些信息都应该在app中设置,如下
CMakeLists.txt
cmake_minimum_required(VERSION 3.1.0)
project(example VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(target example)
set(CMAKE_AUTOMOC ON) # support qt moc
set(CMAKE_AUTORCC ON) # support qt resource file
set(CMAKE_AUTOUIC ON) # support qt ui file
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # suppot clangd
if (CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Gui REQUIRED)
find_package(Dtk COMPONENTS Widget REQUIRED)
find_package(Dtk COMPONENTS Core REQUIRED)
find_package(Dtk COMPONENTS Gui)
add_executable(example
widget.hpp
widget.cpp
main.cpp
)
target_link_libraries(example PRIVATE
Qt5::Widgets
Qt5::Gui
dtkgui
dtkcore
dtkwidget
)
main.cpp
#include <DAboutDialog>
#include <DApplication>
#include "widget.hpp"
DWIDGET_USE_NAMESPACE
int main(int argc, char *argv[])
{
example example1;
example1.show();
a.setApplicationName("dtk example");
}
widget.hpp
#ifndef EXAMPLE_H
#define EXAMPLE_H
#include <DPushButton>
#include <DLineEdit>
#include <DLabel>
#include <QVBoxLayout>
#include <DMainWindow>
DWIDGET_USE_NAMESPACE
{
Q_OBJECT
public:
example();
~example();
private:
QVBoxLayout *mainlayout;
DPushButton *button;
private slots:
void printlog();
};
#endif
The DMainWindow class provides a main application window.
Definition dmainwindow.h:20
widget.cpp
#include "widget.hpp"
#include <cstdio>
#include <QDebug>
example::example()
{
mainlayout= new QVBoxLayout;
button = new DPushButton;
mainlayout->addWidget(label);
mainlayout->addWidget(text);
mainlayout->addWidget(button);
setLayout(mainlayout);
connect(button,SIGNAL(clicked()),this,SLOT(printlog()));
}
example::~example(){}
void example::printlog()
{
printf("%s\n","clicked");
qDebug() << "button clicked!";
}
效果如下图
example