Custom render tooltip events in RDHeaderView

* Because Qt is awful at customising controls, the functions used to fetch the
  index of sections are not virtual so the internal QHeaderView version doesn't
  get the right sections when we have column grouping enabled.
This commit is contained in:
baldurk
2026-08-05 10:45:07 +01:00
parent 3b1a832a57
commit 28c6f55800
2 changed files with 24 additions and 0 deletions
@@ -30,6 +30,7 @@
#include <QPixmap>
#include <QPointer>
#include <QScrollBar>
#include <QToolTip>
#include <QTreeView>
#include "Code/QRDUtils.h"
@@ -864,6 +865,28 @@ void RDHeaderView::paintEvent(QPaintEvent *e)
}
}
bool RDHeaderView::viewportEvent(QEvent *e)
{
if(e->type() == QEvent::ToolTip)
{
QHelpEvent *h = (QHelpEvent *)e;
int section = logicalIndexAt(h->pos());
if(section >= 0)
{
QAbstractItemModel *m = this->model();
QVariant tooltip = m->headerData(section, orientation(), Qt::ToolTipRole);
if(tooltip.isValid())
{
QToolTip::showText(h->globalPos(), tooltip.toString(), this);
return true;
}
}
}
return QHeaderView::viewportEvent(e);
}
void RDHeaderView::paintSection(QPainter *painter, const QRect &rect, int section) const
{
if(!m_customSizing)
@@ -79,6 +79,7 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void paintEvent(QPaintEvent *e) override;
bool viewportEvent(QEvent *e) override;
void paintSection(QPainter *painter, const QRect &rect, int section) const override;
void currentChanged(const QModelIndex &current, const QModelIndex &old) override;