summaryrefslogtreecommitdiffstats
path: root/tests/auto/qstyle
diff options
context:
space:
mode:
authorAndy Shaw <qt-info@nokia.com>2010-10-04 13:10:25 (GMT)
committerAndy Shaw <qt-info@nokia.com>2010-10-04 13:10:25 (GMT)
commita636fa9006b7f4cb898cdeec38a99c994fd9259e (patch)
tree474cd85aade64e791c21bdc81ce77b462137d427 /tests/auto/qstyle
parentd203e7d078cc2bb43ccb32282f40cedbffee4095 (diff)
downloadQt-a636fa9006b7f4cb898cdeec38a99c994fd9259e.zip
Qt-a636fa9006b7f4cb898cdeec38a99c994fd9259e.tar.gz
Qt-a636fa9006b7f4cb898cdeec38a99c994fd9259e.tar.bz2
Ensure that the underline is only drawn when expected for an accel
On Mac, the underline for an accel should not be drawn at all as this is not part of the style guidelines. This ensures that it is not drawn. Autotest included which required a change to drawItemText() to go via the proxy as well so that the autotest would be useful too. Task-number: QTBUG-14172 Reviewed-by: Richard
Diffstat (limited to 'tests/auto/qstyle')
-rw-r--r--tests/auto/qstyle/tst_qstyle.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qstyle/tst_qstyle.cpp b/tests/auto/qstyle/tst_qstyle.cpp
index a76c82d..ba24225 100644
--- a/tests/auto/qstyle/tst_qstyle.cpp
+++ b/tests/auto/qstyle/tst_qstyle.cpp
@@ -53,6 +53,7 @@
#include <qscrollbar.h>
#include <qprogressbar.h>
#include <qtoolbutton.h>
+#include <qtoolbar.h>
#include <qplastiquestyle.h>
#include <qwindowsstyle.h>
@@ -146,6 +147,7 @@ private slots:
void pixelMetric();
void progressBarChangeStyle();
void defaultFont();
+ void testDrawingShortcuts();
private:
void lineUpLayoutTest(QStyle *);
QWidget *testWidget;
@@ -781,5 +783,54 @@ void tst_QStyle::defaultFont()
qApp->setFont(defaultFont);
}
+class DrawTextStyle : public QProxyStyle
+{
+ Q_OBJECT
+public:
+ DrawTextStyle(QStyle *base = 0) : QProxyStyle(), alignment(0) { setBaseStyle(base); }
+ void drawItemText(QPainter *painter, const QRect &rect,
+ int flags, const QPalette &pal, bool enabled,
+ const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const
+ {
+ DrawTextStyle *that = (DrawTextStyle *)this;
+ that->alignment = flags;
+ QProxyStyle::drawItemText(painter, rect, flags, pal, enabled, text, textRole);
+ }
+ int alignment;
+};
+
+void tst_QStyle::testDrawingShortcuts()
+{
+ {
+ QWidget w;
+ QToolButton *tb = new QToolButton(&w);
+ tb->setText("&abc");
+ DrawTextStyle *dts = new DrawTextStyle;
+ w.show();
+ tb->setStyle(dts);
+ QPixmap::grabWidget(tb);
+ QStyleOptionToolButton sotb;
+ sotb.initFrom(tb);
+ bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
+ QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
+ delete dts;
+ }
+ {
+ QToolBar w;
+ QToolButton *tb = new QToolButton(&w);
+ tb->setText("&abc");
+ DrawTextStyle *dts = new DrawTextStyle;
+ w.addWidget(tb);
+ w.show();
+ tb->setStyle(dts);
+ QPixmap::grabWidget(tb);
+ QStyleOptionToolButton sotb;
+ sotb.initFrom(tb);
+ bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
+ QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
+ delete dts;
+ }
+}
+
QTEST_MAIN(tst_QStyle)
#include "tst_qstyle.moc"