summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/kernel/qapplication.cpp11
-rw-r--r--src/widgets/styles/qcommonstyle.cpp8
-rw-r--r--src/widgets/styles/qstyle.cpp6
-rw-r--r--src/widgets/styles/qstyle.h2
-rw-r--r--tests/manual/widgets/kernel/qtooltip/main.cpp59
5 files changed, 80 insertions, 6 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index adccee9426..cb2eab8468 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -1852,8 +1852,11 @@ bool QApplication::event(QEvent *e)
if (showToolTip) {
QHelpEvent e(QEvent::ToolTip, d->toolTipPos, d->toolTipGlobalPos);
QApplication::sendEvent(d->toolTipWidget, &e);
- if (e.isAccepted())
- d->toolTipFallAsleep.start(2000, this);
+ if (e.isAccepted()) {
+ QStyle *s = d->toolTipWidget->style();
+ int sleepDelay = s->styleHint(QStyle::SH_ToolTip_FallAsleepDelay, 0, d->toolTipWidget, 0);
+ d->toolTipFallAsleep.start(sleepDelay, this);
+ }
}
}
} else if (te->timerId() == d->toolTipFallAsleep.timerId()) {
@@ -2956,7 +2959,9 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
d->toolTipWidget = w;
d->toolTipPos = relpos;
d->toolTipGlobalPos = mouse->globalPos();
- d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive()?20:700, this);
+ QStyle *s = d->toolTipWidget->style();
+ int wakeDelay = s->styleHint(QStyle::SH_ToolTip_WakeUpDelay, 0, d->toolTipWidget, 0);
+ d->toolTipWakeUp.start(d->toolTipFallAsleep.isActive() ? 20 : wakeDelay, this);
}
}
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index f19df120ba..262275611c 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -5105,6 +5105,14 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
case SH_Menu_SupportsSections:
ret = false;
break;
+#ifndef QT_NO_TOOLTIP
+ case SH_ToolTip_WakeUpDelay:
+ ret = 700;
+ break;
+ case SH_ToolTip_FallAsleepDelay:
+ ret = 2000;
+ break;
+#endif
default:
ret = 0;
break;
diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp
index c6c71845eb..826a05db51 100644
--- a/src/widgets/styles/qstyle.cpp
+++ b/src/widgets/styles/qstyle.cpp
@@ -1894,6 +1894,12 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value SH_Menu_SupportsSections Determines if the style displays sections in menus or treat them as
plain separators. Sections are separators with a text and icon hint.
+ \value SH_ToolTip_WakeUpDelay Determines the delay before a tooltip is shown, in milliseconds.
+
+ \value SH_ToolTip_FallAsleepDelay Determines the delay (in milliseconds) before a new wake time is needed when
+ a tooltip is shown (notice: shown, not hidden). When a new wake isn't needed, a user-requested tooltip
+ will be shown nearly instantly.
+
\sa styleHint()
*/
diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h
index 31ec2cd97a..d4e1be4787 100644
--- a/src/widgets/styles/qstyle.h
+++ b/src/widgets/styles/qstyle.h
@@ -698,6 +698,8 @@ public:
SH_RequestSoftwareInputPanel,
SH_ScrollBar_Transient,
SH_Menu_SupportsSections,
+ SH_ToolTip_WakeUpDelay,
+ SH_ToolTip_FallAsleepDelay,
// Add new style hint values here
SH_CustomBase = 0xf0000000
diff --git a/tests/manual/widgets/kernel/qtooltip/main.cpp b/tests/manual/widgets/kernel/qtooltip/main.cpp
index d0f0db8ff5..a7a2b9915c 100644
--- a/tests/manual/widgets/kernel/qtooltip/main.cpp
+++ b/tests/manual/widgets/kernel/qtooltip/main.cpp
@@ -45,12 +45,46 @@
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
+#include <QProxyStyle>
+#include <QSpinBox>
+
+class QToolTipTest : public QProxyStyle
+{
+ Q_OBJECT
+public:
+ QToolTipTest() : QProxyStyle()
+ {
+ wakeTime = QApplication::style()->styleHint(SH_ToolTip_WakeUpDelay);
+ sleepTime = QApplication::style()->styleHint(SH_ToolTip_FallAsleepDelay);
+ }
+
+ int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0,
+ QStyleHintReturn *returnData = 0) const
+ {
+ switch (hint) {
+ case SH_ToolTip_WakeUpDelay:
+ return wakeTime;
+ case SH_ToolTip_FallAsleepDelay:
+ return sleepTime;
+ default:
+ return QProxyStyle::styleHint(hint, option, widget, returnData);
+ }
+ }
+
+public slots:
+ void setWakeTime(int wake) { wakeTime = wake; }
+ void setSleepTime(int sleep) { sleepTime = sleep; }
+protected:
+ int wakeTime;
+ int sleepTime;
+};
class TestDialog : public QDialog
{
Q_OBJECT
public:
- TestDialog();
+ TestDialog(QToolTipTest *s);
+ QToolTipTest *style;
protected slots:
void showSomeToolTips();
};
@@ -72,7 +106,7 @@ void TestDialog::showSomeToolTips()
QTest::qWait(12000);
}
-TestDialog::TestDialog()
+TestDialog::TestDialog(QToolTipTest *s) : style(s)
{
// Notice that these tool tips will disappear if another tool tip is shown.
QLabel *label1 = new QLabel(tr("Tooltip - Only two seconds display"));
@@ -89,10 +123,27 @@ TestDialog::TestDialog()
Q_ASSERT(pb->toolTipDuration() == -1);
connect(pb, SIGNAL(clicked()), this, SLOT(showSomeToolTips()));
+ QLabel *wakeLabel = new QLabel(tr("Wake Delay:"));
+ QSpinBox *wakeSpinBox = new QSpinBox();
+ wakeSpinBox->setRange(0, 100000);
+ wakeSpinBox->setValue(style->styleHint(QStyle::SH_ToolTip_WakeUpDelay));
+ connect(wakeSpinBox, SIGNAL(valueChanged(int)), style, SLOT(setWakeTime(int)));
+
+ QLabel *sleepLabel = new QLabel(tr("Sleep Delay:"));
+ QSpinBox *sleepSpinBox = new QSpinBox();
+ sleepSpinBox->setRange(0, 100000);
+ sleepSpinBox->setValue(style->styleHint(QStyle::SH_ToolTip_FallAsleepDelay));
+ connect(sleepSpinBox, SIGNAL(valueChanged(int)), style, SLOT(setSleepTime(int)));
+
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(label1);
layout->addWidget(label2);
layout->addWidget(pb);
+ layout->addWidget(wakeLabel);
+ layout->addWidget(wakeSpinBox);
+ layout->addWidget(wakeLabel);
+ layout->addWidget(sleepLabel);
+ layout->addWidget(sleepSpinBox);
setLayout(layout);
}
@@ -100,7 +151,9 @@ TestDialog::TestDialog()
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- TestDialog dlg;
+ QToolTipTest *style = new QToolTipTest();
+ QApplication::setStyle(style);
+ TestDialog dlg(style);
dlg.show();
return app.exec();
}