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/an...rd_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
) {
adjustedPos.setX(adjustedPos.x()-lineNumberAreaWidth());
QToolTip::showText(globalpos, cursor.
selectedText());
}
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());
}
To copy to clipboard, switch view to plain text mode
And see the result:
screen.jpg
The word displayed is the correct word, but the position is wrong...
Bookmarks