Allow to style arrows drawn with drawPrimitive in QCommonStyle.
Its currently not possible to style the arrows with QCommonStyle because drawPrimitive from QCommonStyle is called instead from the proxy. Change-Id: I910b13df110601cb18578bc16edfa5ddaa17bbd2 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
705d29585b
commit
f64640f441
@ -1597,7 +1597,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
|
|||||||
if (!hasArrow) {
|
if (!hasArrow) {
|
||||||
proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pm);
|
proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pm);
|
||||||
} else {
|
} else {
|
||||||
drawArrow(this, toolbutton, pr, p, widget);
|
drawArrow(proxy(), toolbutton, pr, p, widget);
|
||||||
}
|
}
|
||||||
alignment |= Qt::AlignCenter;
|
alignment |= Qt::AlignCenter;
|
||||||
} else {
|
} else {
|
||||||
@ -1607,7 +1607,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
|
|||||||
if (!hasArrow) {
|
if (!hasArrow) {
|
||||||
proxy()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, pr), Qt::AlignCenter, pm);
|
proxy()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, pr), Qt::AlignCenter, pm);
|
||||||
} else {
|
} else {
|
||||||
drawArrow(this, toolbutton, pr, p, widget);
|
drawArrow(proxy(), toolbutton, pr, p, widget);
|
||||||
}
|
}
|
||||||
alignment |= Qt::AlignLeft | Qt::AlignVCenter;
|
alignment |= Qt::AlignLeft | Qt::AlignVCenter;
|
||||||
}
|
}
|
||||||
@ -1618,7 +1618,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
|
|||||||
} else {
|
} else {
|
||||||
rect.translate(shiftX, shiftY);
|
rect.translate(shiftX, shiftY);
|
||||||
if (hasArrow) {
|
if (hasArrow) {
|
||||||
drawArrow(this, toolbutton, rect, p, widget);
|
drawArrow(proxy(), toolbutton, rect, p, widget);
|
||||||
} else {
|
} else {
|
||||||
proxy()->drawItemPixmap(p, rect, Qt::AlignCenter, pm);
|
proxy()->drawItemPixmap(p, rect, Qt::AlignCenter, pm);
|
||||||
}
|
}
|
||||||
|
@ -131,6 +131,8 @@ private slots:
|
|||||||
void defaultFont();
|
void defaultFont();
|
||||||
void testDrawingShortcuts();
|
void testDrawingShortcuts();
|
||||||
void testFrameOnlyAroundContents();
|
void testFrameOnlyAroundContents();
|
||||||
|
|
||||||
|
void testProxyCalled();
|
||||||
private:
|
private:
|
||||||
void lineUpLayoutTest(QStyle *);
|
void lineUpLayoutTest(QStyle *);
|
||||||
QWidget *testWidget;
|
QWidget *testWidget;
|
||||||
@ -808,5 +810,51 @@ void tst_QStyle::testFrameOnlyAroundContents()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ProxyTest: public QProxyStyle
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ProxyTest(QStyle *style = 0)
|
||||||
|
:QProxyStyle(style)
|
||||||
|
, called(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const Q_DECL_OVERRIDE {
|
||||||
|
called = true;
|
||||||
|
return QProxyStyle::drawPrimitive(pe, opt, p, w);
|
||||||
|
}
|
||||||
|
mutable bool called;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void tst_QStyle::testProxyCalled()
|
||||||
|
{
|
||||||
|
QToolButton b;
|
||||||
|
b.setArrowType(Qt::DownArrow);
|
||||||
|
QStyleOptionToolButton opt;
|
||||||
|
opt.init(&b);
|
||||||
|
opt.features |= QStyleOptionToolButton::Arrow;
|
||||||
|
QPixmap surface(QSize(200, 200));
|
||||||
|
QPainter painter(&surface);
|
||||||
|
|
||||||
|
QStringList keys = QStyleFactory::keys();
|
||||||
|
QVector<QStyle*> styles;
|
||||||
|
styles.reserve(keys.size() + 1);
|
||||||
|
|
||||||
|
styles << new QCommonStyle();
|
||||||
|
|
||||||
|
Q_FOREACH (const QString &key, keys) {
|
||||||
|
styles << QStyleFactory::create(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_FOREACH (QStyle *style, styles) {
|
||||||
|
ProxyTest testStyle;
|
||||||
|
testStyle.setBaseStyle(style);
|
||||||
|
style->drawControl(QStyle::CE_ToolButtonLabel, &opt, &painter, &b);
|
||||||
|
QVERIFY(testStyle.called);
|
||||||
|
delete style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QStyle)
|
QTEST_MAIN(tst_QStyle)
|
||||||
#include "tst_qstyle.moc"
|
#include "tst_qstyle.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user