左侧为自定义,右侧为原始
通过QDockWidget::setTitleBarWidget()实现标题栏自定义
MDockWidget.cpp
#include "MDockWidget.h"
#include <QtWidgets/QDockWidget>
#include <QtWidgets/QAbstractButton>
#include <QtWidgets/QStyleOptionDockWidget>
MDockWidget::MDockWidget(QWidget* parent, Qt::WindowFlags flags)
: MDockWidget("", parent, flags)
{
}
MDockWidget::MDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
: QDockWidget(title, parent, flags)
{
m_titleBar = new MDockTitleBar(title, this);
setTitleBarWidget(m_titleBar);
auto floatButton = findChild<QAbstractButton*>("qt_dockwidget_floatbutton");
if(nullptr != floatButton) {
connect(m_titleBar, &MDockTitleBar::floatingClicked, this, [this, floatButton