nekkro-kvlt
18th February 2012, 15:22
Hi all,
I have a weird issue. I'm trying to display a tooltip on a QPlainTextEdit subclass, and the tooltip is shown too much above the mouse cursor. I'm currently showing the word under the mouse cursor. I basically used the code here:
http://developer.qt.nokia.com/faq/answer/how_can_i_display_a_tooltip_over_only_one_word_in_ a_qlabel
bool logEditor::event(QEvent *event)
{
if (event->type() == QEvent::ToolTip)
{
processTooltip(static_cast <QHelpEvent*>(event)->pos(),static_cast <QHelpEvent*>(event)->globalPos());
return true;
}
return QPlainTextEdit::event(event);
}
void logEditor::processTooltip(QPoint pos, QPoint globalpos)
{
QPoint adjustedPos=pos;
adjustedPos.setX(adjustedPos.x()-lineNumberAreaWidth());
QTextCursor cursor = cursorForPosition(adjustedPos);
cursor.select(QTextCursor::WordUnderCursor);
QToolTip::showText(globalpos, cursor.selectedText());
}
And see the result:
7414
The word displayed is the correct word, but the position is wrong...
I have a weird issue. I'm trying to display a tooltip on a QPlainTextEdit subclass, and the tooltip is shown too much above the mouse cursor. I'm currently showing the word under the mouse cursor. I basically used the code here:
http://developer.qt.nokia.com/faq/answer/how_can_i_display_a_tooltip_over_only_one_word_in_ a_qlabel
bool logEditor::event(QEvent *event)
{
if (event->type() == QEvent::ToolTip)
{
processTooltip(static_cast <QHelpEvent*>(event)->pos(),static_cast <QHelpEvent*>(event)->globalPos());
return true;
}
return QPlainTextEdit::event(event);
}
void logEditor::processTooltip(QPoint pos, QPoint globalpos)
{
QPoint adjustedPos=pos;
adjustedPos.setX(adjustedPos.x()-lineNumberAreaWidth());
QTextCursor cursor = cursorForPosition(adjustedPos);
cursor.select(QTextCursor::WordUnderCursor);
QToolTip::showText(globalpos, cursor.selectedText());
}
And see the result:
7414
The word displayed is the correct word, but the position is wrong...