forked from qt-creator/qt-creator
CodeAssist: Limit width of tooltips
This is a workaround for black tooltips or even crahes when the nvidia driver is used. Task-number: QTCREATORBUG-11653 Change-Id: I4ddc09354a9956a55ac6b196a596f3eaeef13670 Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include <texteditor/completionsettings.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
|
||||
#include <utils/elidinglabel.h>
|
||||
#include <utils/faketooltip.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
@@ -150,13 +151,16 @@ class GenericProposalInfoFrame : public Utils::FakeToolTip
|
||||
{
|
||||
public:
|
||||
GenericProposalInfoFrame(QWidget *parent = 0)
|
||||
: Utils::FakeToolTip(parent), m_label(new QLabel(this))
|
||||
: Utils::FakeToolTip(parent), m_label(new Utils::ElidingLabel(this))
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setMargin(0);
|
||||
layout->setSpacing(0);
|
||||
layout->addWidget(m_label);
|
||||
|
||||
// Limit horizontal width
|
||||
m_label->setSizePolicy(QSizePolicy::Fixed, m_label->sizePolicy().verticalPolicy());
|
||||
|
||||
m_label->setForegroundRole(QPalette::ToolTipText);
|
||||
m_label->setBackgroundRole(QPalette::ToolTipBase);
|
||||
}
|
||||
@@ -166,6 +170,20 @@ public:
|
||||
m_label->setText(text);
|
||||
}
|
||||
|
||||
// Workaround QTCREATORBUG-11653
|
||||
void calculateMaximumWidth()
|
||||
{
|
||||
const QDesktopWidget *desktopWidget = QApplication::desktop();
|
||||
const int desktopWidth = desktopWidget->isVirtualDesktop()
|
||||
? desktopWidget->width()
|
||||
: desktopWidget->availableGeometry(desktopWidget->primaryScreen()).width();
|
||||
const QMargins widgetMargins = contentsMargins();
|
||||
const QMargins layoutMargins = layout()->contentsMargins();
|
||||
const int margins = widgetMargins.left() + widgetMargins.right()
|
||||
+ layoutMargins.left() + layoutMargins.right();
|
||||
m_label->setMaximumWidth(desktopWidth - this->pos().x() - margins);
|
||||
}
|
||||
|
||||
private:
|
||||
QLabel *m_label;
|
||||
};
|
||||
@@ -296,6 +314,7 @@ void GenericProposalWidgetPrivate::maybeShowInfoTip()
|
||||
|
||||
m_infoFrame->move(m_completionListView->infoFramePos());
|
||||
m_infoFrame->setText(infoTip);
|
||||
m_infoFrame->calculateMaximumWidth();
|
||||
m_infoFrame->adjustSize();
|
||||
m_infoFrame->show();
|
||||
m_infoFrame->raise();
|
||||
|
||||
Reference in New Issue
Block a user