Skip to content

Commit

Permalink
Refs #10408 Use QLabel to show hints
Browse files Browse the repository at this point in the history
Instead of relying on QToolTip (which has problems on OSX), create a
QLabel widget and style it to look like a tooltip.
  • Loading branch information
Harry Jeffery committed Oct 29, 2014
1 parent 524f81d commit 9bc29d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Expand Up @@ -57,6 +57,7 @@ namespace MantidQt
std::map<std::string,std::string> m_matches;
std::map<std::string,std::string> m_hints;
bool m_dontComplete;
QLabel* m_hintLabel;
protected slots:
void updateHints(const QString& text);
};
Expand Down
24 changes: 23 additions & 1 deletion Code/Mantid/MantidQt/MantidWidgets/src/HintingLineEdit.cpp
Expand Up @@ -9,6 +9,18 @@ namespace MantidQt
{
HintingLineEdit::HintingLineEdit(QWidget *parent, const std::map<std::string,std::string> &hints) : QLineEdit(parent), m_hints(hints), m_dontComplete(false)
{
m_hintLabel = new QLabel(this, Qt::ToolTip);
m_hintLabel->setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, m_hintLabel));
m_hintLabel->setFrameStyle(QFrame::StyledPanel);
m_hintLabel->setAlignment(Qt::AlignLeft);
m_hintLabel->setWordWrap(true);
m_hintLabel->setIndent(1);
m_hintLabel->setAutoFillBackground(true);
m_hintLabel->setPalette(QToolTip::palette());
m_hintLabel->setForegroundRole(QPalette::ToolTipText);
m_hintLabel->setBackgroundRole(QPalette::ToolTipBase);
m_hintLabel->ensurePolished();

connect(this, SIGNAL(textEdited(const QString&)), this, SLOT(updateHints(const QString&)));
}

Expand Down Expand Up @@ -103,7 +115,17 @@ namespace MantidQt
hintList += QString::fromStdString(mIt->second) + "<br />\n";
}

QToolTip::showText(mapToGlobal(QPoint(0, 5)), hintList.trimmed());
if(!hintList.trimmed().isEmpty())
{
m_hintLabel->show();
m_hintLabel->setText(hintList.trimmed());
m_hintLabel->adjustSize();
m_hintLabel->move(mapToGlobal(QPoint(0, height())));
}
else
{
m_hintLabel->hide();
}
}

/** Insert an auto completion suggestion beneath the user's cursor and select it */
Expand Down

0 comments on commit 9bc29d8

Please sign in to comment.