From 5b07158b36b7dcef921d646f00ed4a09b60eb251 Mon Sep 17 00:00:00 2001 From: laserpants Date: Sat, 19 Mar 2016 13:47:39 +0300 Subject: [PATCH] subclass Style from QProxyStyle instead of QCommonStyle --- style.cpp | 51 ++++++++++++++++++++++++++++----------------------- style.h | 5 +++-- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/style.cpp b/style.cpp index e644036..0c96856 100644 --- a/style.cpp +++ b/style.cpp @@ -4,7 +4,7 @@ #include "style.h" Style::Style() - : QCommonStyle() + : QProxyStyle() { } @@ -15,7 +15,7 @@ Style::~Style() void Style::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const { -// qDebug() << pe; + qDebug() << pe; switch (pe) { case PE_FrameFocusRect: @@ -23,31 +23,36 @@ void Style::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter p->drawRect(opt->rect); break; default: - QCommonStyle::drawPrimitive(pe, opt, p, w); + QProxyStyle::drawPrimitive(pe, opt, p, w); } } void Style::drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *widget) const { -// qDebug() << element; + qDebug() << element; switch (element) { /* case CE_FocusFrame: p->fillRect(opt->rect, opt->palette.foreground()); break; + case CE_MenuItem: + if (const QStyleOptionMenuItem *item = qstyleoption_cast(opt)) { + p->drawText(item->rect, item->text); + } + break; */ default: - QCommonStyle::drawControl(element, opt, p, widget); + QProxyStyle::drawControl(element, opt, p, widget); } } QRect Style::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *widget) const { -// qDebug() << "subElementRect : " << sr; -// qDebug() << "-----------------------------------------------"; + qDebug() << "subElementRect : " << sr; + qDebug() << "-----------------------------------------------"; QRect r; switch (sr) { @@ -58,11 +63,11 @@ QRect Style::subElementRect(SubElement sr, const QStyleOption *opt, } break; default: - r = QCommonStyle::subElementRect(sr, opt, widget); + r = QProxyStyle::subElementRect(sr, opt, widget); } -// qDebug() << "r = " << r; -// qDebug() << "==============================================="; + qDebug() << "r = " << r; + qDebug() << "==============================================="; return r; } @@ -70,37 +75,37 @@ QRect Style::subElementRect(SubElement sr, const QStyleOption *opt, void Style::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w) const { -// qDebug() << "drawComplexControl : " << cc; -// qDebug() << "==============================================="; + qDebug() << "drawComplexControl : " << cc; + qDebug() << "==============================================="; switch (cc) { default: - return QCommonStyle::drawComplexControl(cc, opt, p, w); + QProxyStyle::drawComplexControl(cc, opt, p, w); } } QRect Style::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *w) const { -// qDebug() << "subControlRect : " << cc; -// qDebug() << "------------------------------------------------"; + qDebug() << "subControlRect : " << cc; + qDebug() << "------------------------------------------------"; QRect r; switch (cc) { default: - r = QCommonStyle::subControlRect(cc, opt, sc, w); + r = QProxyStyle::subControlRect(cc, opt, sc, w); } -// qDebug() << "r = " << r; -// qDebug() << "==============================================="; + qDebug() << "r = " << r; + qDebug() << "==============================================="; return r; } int Style::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWidget *widget) const { -// qDebug() << "pixelMetric : " << m; -// qDebug() << "-----------------------------------------------"; + qDebug() << "pixelMetric : " << m; + qDebug() << "-----------------------------------------------"; int ret; @@ -111,11 +116,11 @@ int Style::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWidget *wi ret = 0; break; default: - ret = QCommonStyle::pixelMetric(m, opt, widget); + ret = QProxyStyle::pixelMetric(m, opt, widget); } -// qDebug() << "ret = " << ret; -// qDebug() << "==============================================="; + qDebug() << "ret = " << ret; + qDebug() << "==============================================="; return ret; } diff --git a/style.h b/style.h index 7c56da8..417e6f0 100644 --- a/style.h +++ b/style.h @@ -1,9 +1,10 @@ #ifndef STYLE_H #define STYLE_H -#include +#include -class Style : public QCommonStyle +//class Style : public QCommonStyle +class Style : public QProxyStyle { Q_OBJECT