| 1 |
/* Copyright (c) 2023, DyssolTEC. All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */ |
| 2 |
|
| 3 |
#include "QtTooltipMenuBar.h" |
| 4 |
#include <QHelpEvent> |
| 5 |
#include <QToolTip> |
| 6 |
|
| 7 |
CQtTooltipMenuBar::CQtTooltipMenuBar(QWidget* _parent) |
| 8 |
: QMenuBar(_parent) |
| 9 |
{ |
| 10 |
} |
| 11 |
|
| 12 |
bool CQtTooltipMenuBar::event(QEvent* _event) |
| 13 |
{ |
| 14 |
if (_event->type() == QEvent::ToolTip) |
| 15 |
{ |
| 16 |
const QHelpEvent* help = dynamic_cast<QHelpEvent*>(_event); |
| 17 |
const QAction* action = help ? actionAt(help->pos()) : nullptr; |
| 18 |
const QMenu* menu = action ? action->menu() : nullptr; |
| 19 |
if (menu) |
| 20 |
{ |
| 21 |
QToolTip::showText(help->globalPos(), menu->toolTip(), this); |
| 22 |
return true; |
| 23 |
} |
| 24 |
if (_event->type() == QEvent::Paint && QToolTip::isVisible()) |
| 25 |
{ |
| 26 |
QToolTip::hideText(); |
| 27 |
} |
| 28 |
} |
| 29 |
return QMenuBar::event(_event); |
| 30 |
} |