MainWindow: support tooltip for tab bar of dock widgets

This commit is contained in:
Le Tan 2021-08-30 20:59:50 +08:00
parent e4edee269b
commit d8635e957c
3 changed files with 41 additions and 1 deletions

View File

@ -1,4 +1,4 @@
# Welcome To VNote
# Welcome to VNote
A pleasant note-taking platform.
For more information, please visit [**VNote's Home Page**](https://vnotex.github.io/vnote) or [Home Page on Gitee](https://tamlok.gitee.io/vnote).

View File

@ -19,6 +19,8 @@
#include <QWindowStateChangeEvent>
#include <QTimer>
#include <QBitArray>
#include <QHelpEvent>
#include <QToolTip>
#include "toolbox.h"
#include "notebookexplorer.h"
@ -806,6 +808,11 @@ void MainWindow::updateDockWidgetTabBar()
{
QBitArray tabifiedDocks(m_docks.size(), false);
Q_FOREACH(QTabBar* tabBar, this->findChildren<QTabBar*>(QString(), Qt::FindDirectChildrenOnly)) {
if (!m_tabBarsMonitored.contains(tabBar)) {
m_tabBarsMonitored.insert(tabBar);
tabBar->installEventFilter(this);
}
tabBar->setDrawBase(false);
const int sz = ConfigMgr::getInst().getCoreConfig().getDocksTabBarIconSize();
@ -958,3 +965,30 @@ void MainWindow::checkForUpdates()
}
});
}
bool MainWindow::eventFilter(QObject *p_obj, QEvent *p_event)
{
if (p_event->type() == QEvent::ToolTip) {
// The QTabBar of the tabified dock widgets does not show tooltip due to Qt's internal implementation.
auto helpEve = static_cast<QHelpEvent *>(p_event);
auto tabBar = static_cast<QTabBar *>(p_obj);
int idx = tabBar->tabAt(helpEve->pos());
bool done = false;
if (idx > -1) {
auto dock = reinterpret_cast<QDockWidget *>(tabBar->tabData(idx).toULongLong());
if (dock) {
done = true;
QToolTip::showText(helpEve->globalPos(), dock->property(c_propertyDockTitle).toString());
}
}
if (!done) {
QToolTip::hideText();
p_event->ignore();
}
return true;
}
return QMainWindow::eventFilter(p_obj, p_event);
}

View File

@ -4,6 +4,7 @@
#include <QMainWindow>
#include <QSharedPointer>
#include <QBitArray>
#include <QSet>
#include "toolbarhelper.h"
#include "statusbarhelper.h"
@ -88,6 +89,8 @@ namespace vnotex
void changeEvent(QEvent *p_event) Q_DECL_OVERRIDE;
bool eventFilter(QObject *p_obj, QEvent *p_event) Q_DECL_OVERRIDE;
private slots:
void closeOnQuit();
@ -212,6 +215,9 @@ namespace vnotex
QTimer *m_tipsTimer = nullptr;
QStringList m_visibleDocksBeforeExpand;
// We need to install event filter to the tabbar of tabified dock widgets.
QSet<QTabBar *> m_tabBarsMonitored;
};
} // ns vnotex