8#if QT_CONFIG(style_windows) || defined(QT_PLUGIN)
10#include "qapplication.h"
19#include <private/qmenubar_p.h>
21#include "qpaintengine.h"
23#include "qpainterstateguard.h"
24#if QT_CONFIG(rubberband)
25#include "qrubberband.h"
27#include "qstyleoption.h"
33#if QT_CONFIG(mainwindow)
34#include "qmainwindow.h"
37#include "qtextstream.h"
38#include "qpixmapcache.h"
42#if QT_CONFIG(listview)
45#include <private/qmath_p.h>
47#include <QtGui/qpainterpath.h>
48#include <QtGui/qscreen.h>
49#include <QtGui/qstylehints.h>
50#include <QtGui/qwindow.h>
51#include <qpa/qplatformtheme.h>
52#include <qpa/qplatformscreen.h>
53#include <private/qguiapplication_p.h>
54#include <private/qhighdpiscaling_p.h>
55#include <qpa/qplatformintegration.h>
56#include <private/qwidget_p.h>
58#include <private/qstylehelper_p.h>
59#if QT_CONFIG(animation)
60#include <private/qstyleanimation_p.h>
63#include <QtCore/qoperatingsystemversion.h>
71QT_BEGIN_INCLUDE_NAMESPACE
72#include "qt_windows.h"
73QT_END_INCLUDE_NAMESPACE
74# ifndef COLOR_GRADIENTACTIVECAPTION
75# define COLOR_GRADIENTACTIVECAPTION 27
77# ifndef COLOR_GRADIENTINACTIVECAPTION
78# define COLOR_GRADIENTINACTIVECAPTION 28
81Q_GUI_EXPORT HICON qt_pixmapToWinHICON(
const QPixmap &);
84QT_BEGIN_INCLUDE_NAMESPACE
86QT_END_INCLUDE_NAMESPACE
88enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
91
92
94QWindowsStylePrivate::QWindowsStylePrivate() =
default;
97bool QWindowsStylePrivate::hasSeenAlt(
const QWidget *widget)
const
99 widget = widget->window();
100 return seenAlt.contains(widget);
104
105
106bool QWindowsStyle::eventFilter(QObject *o, QEvent *e)
109 if (!o->isWidgetType())
110 return QObject::eventFilter(o, e);
112 QWidget *widget = qobject_cast<QWidget*>(o);
115 case QEvent::KeyPress:
116 if (
static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) {
117 widget = widget->window();
120 const QList<QWidget *> children = widget->findChildren<QWidget *>();
121 auto ignorable = [](QWidget *w) {
122 return w->isWindow() || !w->isVisible();
125 d->seenAlt.append(widget);
129 for (QWidget *w : children) {
135 case QEvent::KeyRelease:
136 if (
static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) {
137 widget = widget->window();
141#if QT_CONFIG(menubar)
142 const QList<QMenuBar *> menuBars = widget->findChildren<QMenuBar *>();
143 for (QWidget *w : menuBars)
150 d->seenAlt.removeAll(widget);
151 d->seenAlt.removeAll(widget->window());
156 return QCommonStyle::eventFilter(o, e);
160
161
162
163
164
165
166
167
168
169
170
171
174
175
176QWindowsStyle::QWindowsStyle() : QCommonStyle(*
new QWindowsStylePrivate)
181
182
183
184
185QWindowsStyle::QWindowsStyle(QWindowsStylePrivate &dd) : QCommonStyle(dd)
191QWindowsStyle::~QWindowsStyle()
196static inline QRgb colorref2qrgb(COLORREF col)
198 return qRgb(GetRValue(col), GetGValue(col), GetBValue(col));
203void QWindowsStyle::polish(QApplication *app)
205 QCommonStyle::polish(app);
206 QWindowsStylePrivate *d =
const_cast<QWindowsStylePrivate*>(d_func());
208 if (!proxy()->styleHint(SH_UnderlineShortcut,
nullptr) && app)
209 app->installEventFilter(
this);
211 const auto &palette = QGuiApplication::palette();
212 d->activeGradientCaptionColor = palette.highlight().color();
213 d->activeCaptionColor = d->activeGradientCaptionColor;
214 d->inactiveGradientCaptionColor = palette.dark().color();
215 d->inactiveCaptionColor = d->inactiveGradientCaptionColor;
216 d->inactiveCaptionText = palette.window().color();
219 if (app->desktopSettingsAware()){
220 DWORD activeCaption = GetSysColor(COLOR_ACTIVECAPTION);
221 DWORD gradientActiveCaption = GetSysColor(COLOR_GRADIENTACTIVECAPTION);
222 DWORD inactiveCaption = GetSysColor(COLOR_INACTIVECAPTION);
223 DWORD gradientInactiveCaption = GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
224 DWORD inactiveCaptionText = GetSysColor(COLOR_INACTIVECAPTIONTEXT);
225 d->activeCaptionColor = colorref2qrgb(activeCaption);
226 d->activeGradientCaptionColor = colorref2qrgb(gradientActiveCaption);
227 d->inactiveCaptionColor = colorref2qrgb(inactiveCaption);
228 d->inactiveGradientCaptionColor = colorref2qrgb(gradientInactiveCaption);
229 d->inactiveCaptionText = colorref2qrgb(inactiveCaptionText);
235void QWindowsStyle::unpolish(QApplication *app)
237 QCommonStyle::unpolish(app);
238 app->removeEventFilter(
this);
242void QWindowsStyle::polish(QWidget *widget)
244 QCommonStyle::polish(widget);
248void QWindowsStyle::unpolish(QWidget *widget)
250 QCommonStyle::unpolish(widget);
254
255
256void QWindowsStyle::polish(QPalette &pal)
258 QCommonStyle::polish(pal);
261int QWindowsStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm,
const QStyleOption *,
const QWidget *widget)
269 case QStyle::PM_DockWidgetFrameWidth:
270 return GetSystemMetricsForDpi(SM_CXFRAME, dpi);
272 case QStyle::PM_TitleBarHeight: {
273 const int resizeBorderThickness =
274 GetSystemMetricsForDpi(SM_CXSIZEFRAME, dpi) + GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi);
275 if (widget && (widget->windowType() == Qt::Tool))
276 return GetSystemMetricsForDpi(SM_CYSMCAPTION, dpi) + resizeBorderThickness;
277 return GetSystemMetricsForDpi(SM_CYCAPTION, dpi) + resizeBorderThickness;
280 case QStyle::PM_ScrollBarExtent:
282 NONCLIENTMETRICS ncm;
283 ncm.cbSize =
sizeof(NONCLIENTMETRICS);
284 if (SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0, dpi))
285 return qMax(ncm.iScrollHeight, ncm.iScrollWidth);
289 case QStyle::PM_MdiSubWindowFrameWidth:
290 return GetSystemMetricsForDpi(SM_CYFRAME, dpi);
299 return QWindowsStylePrivate::InvalidMetric;
302int QWindowsStylePrivate::fixedPixelMetric(QStyle::PixelMetric pm)
305 case QStyle::PM_ToolBarItemSpacing:
307 case QStyle::PM_ButtonDefaultIndicator:
308 case QStyle::PM_ButtonShiftHorizontal:
309 case QStyle::PM_ButtonShiftVertical:
310 case QStyle::PM_MenuHMargin:
311 case QStyle::PM_MenuVMargin:
312 case QStyle::PM_ToolBarItemMargin:
314 case QStyle::PM_DockWidgetSeparatorExtent:
317 case QStyle::PM_TabBarTabShiftHorizontal:
319 case QStyle::PM_TabBarTabShiftVertical:
324 case QStyle::PM_SliderLength:
329 case QStyle::PM_MenuBarHMargin:
330 case QStyle::PM_MenuBarVMargin:
331 case QStyle::PM_MenuBarPanelWidth:
333 case QStyle::PM_SmallIconSize:
335 case QStyle::PM_LargeIconSize:
337 case QStyle::PM_DockWidgetTitleMargin:
339 case QStyle::PM_DockWidgetTitleBarButtonMargin:
340 case QStyle::PM_DockWidgetFrameWidth:
344 case QStyle::PM_ToolBarHandleExtent:
349 return QWindowsStylePrivate::InvalidMetric;
352static QScreen *screenOf(
const QWidget *w)
355 if (
auto screen = qt_widget_private(
const_cast<QWidget *>(w))->associatedScreen())
358 return QGuiApplication::primaryScreen();
363qreal QWindowsStylePrivate::nativeMetricScaleFactor(
const QWidget *widget)
365 return qreal(1) / QHighDpiScaling::factor(screenOf(widget));
369
370
371int QWindowsStyle::pixelMetric(PixelMetric pm,
const QStyleOption *opt,
const QWidget *widget)
const
373 int ret = QWindowsStylePrivate::pixelMetricFromSystemDp(pm, opt, widget);
374 if (ret != QWindowsStylePrivate::InvalidMetric)
377 ret = QWindowsStylePrivate::fixedPixelMetric(pm);
378 if (ret != QWindowsStylePrivate::InvalidMetric)
379 return int(QStyleHelper::dpiScaled(ret, opt));
384 case PM_MaximumDragDistance:
385 ret = QCommonStyle::pixelMetric(PM_MaximumDragDistance, opt, widget);
394 case PM_SliderControlThickness:
395 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
396 int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
397 int ticks = sl->tickPosition;
399 if (ticks & QSlider::TicksAbove)
401 if (ticks & QSlider::TicksBelow)
409 if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
410 thick += proxy()->pixelMetric(PM_SliderLength, sl, widget) / 4;
414 thick += (space * 2) / (n + 2);
420 case PM_IconViewIconSize:
421 ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget);
424 case PM_SplitterWidth:
425 ret = QStyleHelper::dpiScaled(4, opt);
429 ret = QCommonStyle::pixelMetric(pm, opt, widget);
437
438
439QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap,
const QStyleOption *opt,
440 const QWidget *widget)
const
442 return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
446int QWindowsStyle::styleHint(StyleHint hint,
const QStyleOption *opt,
const QWidget *widget,
447 QStyleHintReturn *returnData)
const
452 case SH_EtchDisabledText: {
453 const QPalette pal = opt ? opt->palette
454 : widget ? widget->palette()
456 ret = pal.window().color().lightness() > pal.text().color().lightness()
460 case SH_Slider_SnapToValue:
461 case SH_PrintDialog_RightAlignButtons:
462 case SH_FontDialog_SelectAssociatedText:
463 case SH_Menu_AllowActiveAndDisabled:
464 case SH_MenuBar_AltKeyNavigation:
465 case SH_MenuBar_MouseTracking:
466 case SH_Menu_MouseTracking:
467 case SH_ComboBox_ListMouseTracking_Current:
468 case SH_Slider_StopMouseOverSlider:
469 case SH_MainWindow_SpaceBelowMenuBar:
473 case SH_ItemView_ShowDecorationSelected:
474#if QT_CONFIG(listview)
475 if (qobject_cast<
const QListView*>(widget))
479 case SH_ItemView_ChangeHighlightOnFocus:
482 case SH_ToolBox_SelectedPageTitleBold:
487 case SH_UnderlineShortcut:
491 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0);
494 Q_D(
const QWindowsStyle);
495 if (!ret && widget && d) {
496#if QT_CONFIG(menubar)
497 const QMenuBar *menuBar = qobject_cast<
const QMenuBar *>(widget);
498 if (!menuBar && qobject_cast<
const QMenu *>(widget)) {
499 QWidget *w = QApplication::activeWindow();
500 if (w && w != widget)
501 menuBar = w->findChild<QMenuBar *>();
505 if (menuBar->d_func()->keyboardState || d->altDown())
510 if (d->hasSeenAlt(widget)) {
514#if QT_CONFIG(accessibility)
515 if (!ret && opt && opt->type == QStyleOption::SO_MenuItem
516 && QStyleHelper::isInstanceOf(opt->styleObject, QAccessible::MenuItem)
517 && opt->styleObject->property(
"_q_showUnderlined").toBool())
523 case SH_Menu_SubMenuSloppyCloseTimeout:
524 case SH_Menu_SubMenuPopupDelay: {
527 if (SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &delay, 0))
534#if QT_CONFIG(rubberband)
535 case SH_RubberBand_Mask:
536 if (
const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
538 if (rbOpt->shape == QRubberBand::Rectangle) {
540 if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) {
541 mask->region = opt->rect;
543 if (widget && widget->isWindow())
545 mask->region -= opt->rect.adjusted(size, size, -size, -size);
553 ret = QOperatingSystemVersion::currentType() == QOperatingSystemVersion::Windows
554 && QGuiApplication::styleHints()->colorScheme() != Qt::ColorScheme::Dark
555 ? QWizard::AeroStyle : QWizard::ModernStyle;
558 case SH_ItemView_ArrowKeysNavigateIntoChildren:
561 case SH_DialogButtonBox_ButtonsHaveIcons:
565 ret = QCommonStyle::styleHint(hint, opt, widget, returnData);
572void QWindowsStyle::drawPrimitive(PrimitiveElement pe,
const QStyleOption *opt, QPainter *p,
573 const QWidget *w)
const
576 bool doRestore =
false;
579#if QT_CONFIG(toolbar)
580 case PE_IndicatorToolBarSeparator: {
581 QPainterStateGuard psg(p);
582 const QRect &rect = opt->rect;
583 constexpr int margin = 2;
584 if (opt->state & State_Horizontal){
585 const int offset = rect.width() / 2;
586 const auto &tl = rect.topLeft();
587 const auto &bl = rect.bottomLeft();
588 p->setPen(opt->palette.dark().color());
589 p->drawLine(QLine(bl.x() + offset, bl.y() - margin,
590 tl.x() + offset, tl.y() + margin));
591 p->setPen(opt->palette.light().color());
592 p->drawLine(QLine(bl.x() + offset + 1, bl.y() - margin,
593 tl.x() + offset + 1, tl.y() + margin));
596 const int offset = rect.height() / 2;
597 const auto &tl = rect.topLeft();
598 const auto &tr = rect.topRight();
599 p->setPen(opt->palette.dark().color());
600 p->drawLine(QLine(tl.x() + margin, tl.y() + offset,
601 tr.x() - margin, tr.y() + offset));
602 p->setPen(opt->palette.light().color());
603 p->drawLine(QLine(tl.x() + margin, tl.y() + offset + 1,
604 tr.x() - margin, tr.y() + offset + 1));
608 case PE_IndicatorToolBarHandle: {
609 QPainterStateGuard psg(p);
610 p->translate(opt->rect.x(), opt->rect.y());
611 if (opt->state & State_Horizontal) {
612 if (opt->rect.height() > 4) {
613 int x = opt->rect.width() / 2 - 4;
614 if (opt->direction == Qt::RightToLeft)
616 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
617 opt->palette,
false, 1,
nullptr);
618 qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4,
619 opt->palette,
false, 1,
nullptr);
622 if (opt->rect.width() > 4) {
623 int y = opt->rect.height() / 2 - 4;
624 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
625 opt->palette,
false, 1,
nullptr);
626 qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3,
627 opt->palette,
false, 1,
nullptr);
633 case PE_FrameButtonTool:
634 case PE_PanelButtonTool: {
635 QPen oldPen = p->pen();
636#if QT_CONFIG(dockwidget)
637 if (w && w->inherits(
"QDockWidgetTitleButton")) {
638 if (
const QWidget *dw = w->parentWidget())
640 qDrawWinButton(p, opt->rect.adjusted(1, 1, 0, 0), opt->palette, opt->state & (State_Sunken | State_On),
641 &opt->palette.button());
649 bool panel = (pe == PE_PanelButtonTool);
650 if ((!(opt->state & State_Sunken ))
651 && (!(opt->state & State_Enabled)
652 || !(opt->state & State_MouseOver && opt->state & State_AutoRaise))
653 && (opt->state & State_On)) {
654 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
657 fill = opt->palette.brush(QPalette::Button);
661 if (opt->state & (State_Raised | State_Sunken | State_On)) {
662 if (opt->state & State_AutoRaise) {
663 if (opt->state & (State_Enabled | State_Sunken | State_On)){
665 qDrawShadePanel(p, opt->rect, opt->palette,
666 opt->state & (State_Sunken | State_On), 1, &fill);
668 qDrawShadeRect(p, opt->rect, opt->palette,
669 opt->state & (State_Sunken | State_On), 1);
672 p->setPen(opt->palette.button().color());
673 p->drawRect(opt->rect.adjusted(1,1,-2,-2));
676 qDrawWinButton(p, opt->rect, opt->palette,
677 opt->state & (State_Sunken | State_On), panel ? &fill :
nullptr);
680 p->fillRect(opt->rect, fill);
684 case PE_PanelButtonCommand:
685 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
687 State flags = opt->state;
688 QPalette pal = opt->palette;
690 if (! (flags & State_Sunken) && (flags & State_On))
691 fill = QBrush(pal.light().color(), Qt::Dense4Pattern);
693 fill = pal.brush(QPalette::Button);
695 if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
696 p->setPen(pal.dark().color());
698 p->drawRect(r.adjusted(0, 0, -1, -1));
699 }
else if (flags & (State_Raised | State_On | State_Sunken)) {
700 qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On),
703 p->fillRect(r, fill);
707 case PE_FrameDefaultButton: {
708 QPen oldPen = p->pen();
709 p->setPen(QPen(opt->palette.shadow().color(), 0));
710 QRectF rect = opt->rect;
711 const qreal dpi = QStyleHelper::dpi(opt);
712 const qreal topLevelAdjustment = QStyleHelper::dpiScaled(0.5, dpi);
713 const qreal bottomRightAdjustment = QStyleHelper::dpiScaled(-1.5, dpi);
714 rect.adjust(topLevelAdjustment, topLevelAdjustment,
715 bottomRightAdjustment, bottomRightAdjustment);
720 case PE_IndicatorCheckBox: {
722 if (opt->state & State_NoChange)
723 fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern);
724 else if (opt->state & State_Sunken)
725 fill = opt->palette.button();
726 else if (opt->state & State_Enabled)
727 fill = opt->palette.base();
729 fill = opt->palette.window();
732 qDrawWinPanel(p, opt->rect, opt->palette,
true, &fill);
733 if (opt->state & State_NoChange)
734 p->setPen(opt->palette.dark().color());
736 p->setPen(opt->palette.text().color());
739 case PE_IndicatorItemViewItemCheck:
744#if QT_CONFIG(itemviews)
745 if (pe == PE_IndicatorItemViewItemCheck) {
746 const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt);
747 p->setPen(itemViewOpt
748 && itemViewOpt->showDecorationSelected
749 && opt->state & State_Selected
750 ? opt->palette.highlightedText().color()
751 : opt->palette.text().color());
752 if (opt->state & State_NoChange)
753 p->setBrush(opt->palette.brush(QPalette::Button));
754 p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, opt->rect.width() - 2, opt->rect.height() - 2);
757 if (!(opt->state & State_Off)) {
758 std::array<QPointF, 6> points;
759 qreal scaleh = opt->rect.width() / 12.0;
760 qreal scalev = opt->rect.height() / 12.0;
761 points[0] = { opt->rect.x() + qreal(3.5) * scaleh, opt->rect.y() + qreal(5.5) * scalev };
762 points[1] = { points[0].x(), points[0].y() + 2 * scalev };
763 points[2] = { points[1].x() + 2 * scaleh, points[1].y() + 2 * scalev };
764 points[3] = { points[2].x() + 4 * scaleh, points[2].y() - 4 * scalev };
765 points[4] = { points[3].x(), points[3].y() - 2 * scalev };
766 points[5] = { points[4].x() - 4 * scaleh, points[4].y() + 4 * scalev };
767 p->setPen(QPen(opt->palette.text().color(), 0));
768 p->setBrush(opt->palette.text());
769 p->drawPolygon(points.data(),
static_cast<
int>(points.size()));
774 case PE_FrameFocusRect:
775 if (
const QStyleOptionFocusRect *fropt = qstyleoption_cast<
const QStyleOptionFocusRect *>(opt)) {
777 if (!(fropt->state & State_KeyboardFocusChange) && !proxy()->styleHint(SH_UnderlineShortcut, opt, w))
781 p->setBackgroundMode(Qt::TransparentMode);
782 QColor bg_col = fropt->backgroundColor;
783 if (!bg_col.isValid())
784 bg_col = p->background().color();
786 QColor patternCol((bg_col.red() ^ 0xff) & 0xff,
787 (bg_col.green() ^ 0xff) & 0xff,
788 (bg_col.blue() ^ 0xff) & 0xff);
789 p->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
790 p->setBrushOrigin(r.topLeft());
791 p->setPen(Qt::NoPen);
792 p->drawRect(r.left(), r.top(), r.width(), 1);
793 p->drawRect(r.left(), r.bottom(), r.width(), 1);
794 p->drawRect(r.left(), r.top(), 1, r.height());
795 p->drawRect(r.right(), r.top(), 1, r.height());
799 case PE_IndicatorRadioButton:
803 p->setRenderHint(QPainter::Antialiasing,
true);
805 QPointF circleCenter = r.center() + QPoint(1, 1);
806 qreal radius = (r.width() + (r.width() + 1) % 2) / 2.0 - 1;
809 path1.addEllipse(circleCenter, radius, radius);
812 path2.addEllipse(circleCenter, radius, radius);
815 path3.addEllipse(circleCenter, radius, radius);
818 path4.addEllipse(circleCenter, radius, radius);
820 QPolygon topLeftPol, bottomRightPol;
821 topLeftPol.setPoints(3, r.x(), r.y(), r.x(), r.y() + r.height(), r.x() + r.width(), r.y());
822 bottomRightPol.setPoints(3, r.x(), r.y() + r.height(), r.x() + r.width(), r.y() + r.height(), r.x() + r.width(), r.y());
824 p->setClipRegion(QRegion(topLeftPol));
825 p->setPen(opt->palette.dark().color());
826 p->setBrush(opt->palette.dark());
828 p->setPen(opt->palette.shadow().color());
829 p->setBrush(opt->palette.shadow());
832 p->setClipRegion(QRegion(bottomRightPol));
833 p->setPen(opt->palette.light().color());
834 p->setBrush(opt->palette.light());
836 p->setPen(opt->palette.midlight().color());
837 p->setBrush(opt->palette.midlight());
840 QColor fillColor = ((opt->state & State_Sunken) || !(opt->state & State_Enabled)) ?
841 opt->palette.button().color() : opt->palette.base().color();
843 p->setClipping(
false);
844 p->setPen(fillColor);
845 p->setBrush(fillColor);
848 if (opt->state & State_On) {
849 p->setPen(opt->palette.text().color());
850 p->setBrush(opt->palette.text());
858 if (w && w->inherits(
"QComboBoxPrivateContainer")){
859 QStyleOption copy = *opt;
860 copy.state |= State_Raised;
861 proxy()->drawPrimitive(PE_PanelMenu, ©, p, w);
866 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
867 if (frame->lineWidth == 2 || pe == PE_Frame) {
868 QPalette popupPal = frame->palette;
869 if (pe == PE_FrameMenu) {
870 popupPal.setColor(QPalette::Light, frame->palette.window().color());
871 popupPal.setColor(QPalette::Midlight, frame->palette.light().color());
873 if (pe == PE_Frame && (frame->state & State_Raised))
874 qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken);
875 else if (pe == PE_Frame && (frame->state & State_Sunken))
877 popupPal.setColor(QPalette::Midlight, frame->palette.window().color());
878 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
881 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
883 QCommonStyle::drawPrimitive(pe, opt, p, w);
886 QPalette popupPal = opt->palette;
887 p->drawRect(opt->rect);
888 popupPal.setColor(QPalette::Light, opt->palette.window().color());
889 popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
890 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
894 case PE_FrameButtonBevel:
895 case PE_PanelButtonBevel: {
897 bool panel = pe != PE_FrameButtonBevel;
898 p->setBrushOrigin(opt->rect.topLeft());
899 if (!(opt->state & State_Sunken) && (opt->state & State_On))
900 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
902 fill = opt->palette.brush(QPalette::Button);
904 if (opt->state & (State_Raised | State_On | State_Sunken)) {
905 qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
906 panel ? &fill :
nullptr);
909 p->fillRect(opt->rect, fill);
911 p->drawRect(opt->rect);
915 if (w && w->inherits(
"QComboBoxPrivateContainer")){
916 const QBrush menuBackground = opt->palette.base().color();
917 QColor borderColor = opt->palette.window().color();
918 qDrawPlainRect(p, opt->rect, borderColor, 1, &menuBackground);
920 QCommonStyle::drawPrimitive(pe, opt, p, w);
923 case PE_FrameWindow: {
924 QPalette popupPal = opt->palette;
925 popupPal.setColor(QPalette::Light, opt->palette.window().color());
926 popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
927 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
929#if QT_CONFIG(dockwidget)
930 case PE_IndicatorDockWidgetResizeHandle:
932 case PE_FrameDockWidget:
933 if (qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
934 proxy()->drawPrimitive(QStyle::PE_FrameWindow, opt, p, w);
939 case PE_FrameStatusBarItem:
940 qDrawShadePanel(p, opt->rect, opt->palette,
true, 1,
nullptr);
943 case PE_IndicatorProgressChunk:
945 bool vertical =
false, inverted =
false;
946 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
947 vertical = !(pb->state & QStyle::State_Horizontal);
948 inverted = pb->invertedAppearance;
952 int chunksize = proxy()->pixelMetric(PM_ProgressBarChunkWidth, opt, w) - space;
954 if (opt->rect.width() <= chunksize)
958 p->fillRect(opt->rect.x() + space, opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
959 opt->palette.brush(QPalette::Highlight));
961 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
962 opt->palette.brush(QPalette::Highlight));
964 if (opt->rect.height() <= chunksize)
968 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height() - space,
969 opt->palette.brush(QPalette::Highlight));
971 p->fillRect(opt->rect.x(), opt->rect.y() + space, opt->rect.width(), opt->rect.height() - space,
972 opt->palette.brush(QPalette::Highlight));
977 case PE_FrameTabWidget: {
978 qDrawWinButton(p, opt->rect, opt->palette,
false,
nullptr);
982 QCommonStyle::drawPrimitive(pe, opt, p, w);
987void QWindowsStyle::drawControl(ControlElement ce,
const QStyleOption *opt, QPainter *p,
988 const QWidget *widget)
const
991#if QT_CONFIG(rubberband)
993 if (qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
995 QPixmap tiledPixmap(16, 16);
996 QPainter pixmapPainter(&tiledPixmap);
997 pixmapPainter.setPen(Qt::NoPen);
998 pixmapPainter.setBrush(Qt::Dense4Pattern);
999 pixmapPainter.setBackground(Qt::white);
1000 pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
1001 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
1002 pixmapPainter.end();
1003 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
1005 QRect r = opt->rect;
1006 QStyleHintReturnMask mask;
1007 if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
1008 p->setClipRegion(mask.region);
1009 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
1016#if QT_CONFIG(menu) && QT_CONFIG(mainwindow)
1017 case CE_MenuBarEmptyArea:
1018 if (widget && qobject_cast<
const QMainWindow *>(widget->parentWidget())) {
1019 p->fillRect(opt->rect, opt->palette.button());
1020 QPen oldPen = p->pen();
1021 p->setPen(opt->palette.dark().color());
1022 p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight());
1029 if (
const QStyleOptionMenuItem *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
1031 menuitem->rect.getRect(&x, &y, &w, &h);
1032 int tab = menuitem->reservedShortcutWidth;
1033 bool dis = !(menuitem->state & State_Enabled);
1034 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
1035 ? menuitem->checked :
false;
1036 bool act = menuitem->state & State_Selected;
1039 int checkcol = qMax<
int>(menuitem->maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth);
1041 QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
1042 p->fillRect(menuitem->rect.adjusted(0, 0, -1, 0), fill);
1044 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
1045 int yoff = y-1 + h / 2;
1046 p->setPen(menuitem->palette.dark().color());
1047 p->drawLine(x + 2, yoff, x + w - 4, yoff);
1048 p->setPen(menuitem->palette.light().color());
1049 p->drawLine(x + 2, yoff + 1, x + w - 4, yoff + 1);
1053 QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height()));
1054 if (!menuitem->icon.isNull() && checked) {
1056 qDrawShadePanel(p, vCheckRect,
1057 menuitem->palette,
true, 1,
1058 &menuitem->palette.brush(QPalette::Button));
1060 QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern);
1061 qDrawShadePanel(p, vCheckRect, menuitem->palette,
true, 1, &fill);
1064 p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
1070 if (!menuitem->icon.isNull()) {
1071 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1073 mode = QIcon::Active;
1074 const auto size = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
1075 const auto dpr = QStyleHelper::getDpr(p);
1076 const auto state = checked ? QIcon::On : QIcon::Off;
1077 const auto pixmap = menuitem->icon.pixmap(QSize(size, size), dpr, mode, state);
1078 QRect pmr(QPoint(0, 0), pixmap.deviceIndependentSize().toSize());
1079 pmr.moveCenter(vCheckRect.center());
1080 p->setPen(menuitem->palette.text().color());
1081 p->drawPixmap(pmr.topLeft(), pixmap);
1082 }
else if (checked) {
1083 QStyleOptionMenuItem newMi = *menuitem;
1084 newMi.state = State_None;
1086 newMi.state |= State_Enabled;
1088 newMi.state |= State_On | State_Selected;
1089 newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + QWindowsStylePrivate::windowsItemFrame,
1090 menuitem->rect.y() + QWindowsStylePrivate::windowsItemFrame,
1091 checkcol - 2 * QWindowsStylePrivate::windowsItemFrame,
1092 menuitem->rect.height() - 2 * QWindowsStylePrivate::windowsItemFrame));
1093 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget);
1095 p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
1099 discol = menuitem->palette.text().color();
1103 int xm =
int(QWindowsStylePrivate::windowsItemFrame) + checkcol +
int(QWindowsStylePrivate::windowsItemHMargin);
1104 int xpos = menuitem->rect.x() + xm;
1105 QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin,
1106 w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin);
1107 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
1108 QStringView s(menuitem->text);
1111 qsizetype t = s.indexOf(u'\t');
1112 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1113 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
1114 text_flags |= Qt::TextHideMnemonic;
1115 text_flags |= Qt::AlignLeft;
1117 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
1118 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
1119 const QString textToDraw = s.mid(t + 1).toString();
1120 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1121 p->setPen(menuitem->palette.light().color());
1122 p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
1125 p->drawText(vShortcutRect, text_flags, textToDraw);
1128 QFont font = menuitem->font;
1129 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1132 const QString textToDraw = s.left(t).toString();
1133 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1134 p->setPen(menuitem->palette.light().color());
1135 p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
1138 p->drawText(vTextRect, text_flags, textToDraw);
1141 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {
1142 int dim = (h - 2 * QWindowsStylePrivate::windowsItemFrame) / 2;
1143 PrimitiveElement arrow;
1144 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1145 xpos = x + w - QWindowsStylePrivate::windowsArrowHMargin - QWindowsStylePrivate::windowsItemFrame - dim;
1146 QRect vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
1147 QStyleOptionMenuItem newMI = *menuitem;
1148 newMI.rect = vSubMenuRect;
1149 newMI.state = dis ? State_None : State_Enabled;
1151 newMI.palette.setColor(QPalette::ButtonText,
1152 newMI.palette.highlightedText().color());
1153 proxy()->drawPrimitive(arrow, &newMI, p, widget);
1159#if QT_CONFIG(menubar)
1160 case CE_MenuBarItem:
1161 if (
const QStyleOptionMenuItem *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
1162 const bool active = mbi->state & State_Selected;
1163 const QBrush buttonBrush = mbi->palette.brush(QPalette::Button);
1164 QStyleOptionMenuItem newMbi = *mbi;
1165 p->fillRect(mbi->rect, buttonBrush);
1167 const bool hasFocus = mbi->state & State_HasFocus;
1168 const bool down = mbi->state & State_Sunken;
1169 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
1172 p->setBrushOrigin(p->brushOriginF() + QPointF(1, 1));
1175 qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(),
1176 mbi->rect.height(), mbi->palette, active && down, 1, 0, &buttonBrush);
1178 newMbi.rect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, mbi, widget),
1179 proxy()->pixelMetric(PM_ButtonShiftVertical, mbi, widget));
1181 QCommonStyle::drawControl(ce, &newMbi, p, widget);
1185#if QT_CONFIG(tabbar)
1186 case CE_TabBarTabShape:
1187 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1188 bool rtlHorTabs = (tab->direction == Qt::RightToLeft
1189 && (tab->shape == QTabBar::RoundedNorth
1190 || tab->shape == QTabBar::RoundedSouth));
1191 bool selected = tab->state & State_Selected;
1192 bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
1194 && tab->position == QStyleOptionTab::Beginning));
1195 bool firstTab = ((!rtlHorTabs
1196 && tab->position == QStyleOptionTab::Beginning)
1198 && tab->position == QStyleOptionTab::End));
1199 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1200 bool previousSelected =
1202 && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
1204 && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
1207 && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
1209 && tab->selectedPosition
1210 == QStyleOptionTab::PreviousIsSelected));
1211 int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget);
1212 bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
1214 && tabBarAlignment == Qt::AlignRight);
1216 bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
1218 && tabBarAlignment == Qt::AlignLeft);
1220 QColor light = tab->palette.light().color();
1221 QColor dark = tab->palette.dark().color();
1222 QColor shadow = tab->palette.shadow().color();
1223 int borderThinkness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
1225 borderThinkness /= 2;
1226 QRect r2(opt->rect);
1228 int x2 = r2.right();
1230 int y2 = r2.bottom();
1231 switch (tab->shape) {
1233 QCommonStyle::drawControl(ce, tab, p, widget);
1235 case QTabBar::RoundedNorth: {
1238 x1 += onlyOne || firstTab ? borderThinkness : 0;
1239 x2 -= onlyOne || lastTab ? borderThinkness : 0;
1242 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.window());
1246 p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.window());
1247 p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.window());
1250 if (firstTab || selected || onlyOne || !previousSelected) {
1252 p->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1253 p->drawPoint(x1 + 1, y1 + 1);
1257 int beg = x1 + (previousSelected ? 0 : 2);
1258 int end = x2 - (nextSelected ? 0 : 2);
1260 p->drawLine(beg, y1, end, y1);
1263 if (lastTab || selected || onlyOne || !nextSelected) {
1265 p->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1266 p->drawPoint(x2 - 1, y1 + 1);
1268 p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1271 case QTabBar::RoundedSouth: {
1274 x1 += firstTab ? borderThinkness : 0;
1275 x2 -= lastTab ? borderThinkness : 0;
1278 p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window());
1282 p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.window());
1283 p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.window());
1286 if (firstTab || selected || onlyOne || !previousSelected) {
1288 p->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1289 p->drawPoint(x1 + 1, y2 - 1);
1293 int beg = x1 + (previousSelected ? 0 : 2);
1294 int end = x2 - (nextSelected ? 0 : 2);
1296 p->drawLine(beg, y2, end, y2);
1298 p->drawLine(beg, y2 - 1, end, y2 - 1);
1301 if (lastTab || selected || onlyOne || !nextSelected) {
1303 p->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1304 p->drawPoint(x2 - 1, y2 - 1);
1306 p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1309 case QTabBar::RoundedWest: {
1312 y1 += firstTab ? borderThinkness : 0;
1313 y2 -= lastTab ? borderThinkness : 0;
1316 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.window());
1320 p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.window());
1321 p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.window());
1324 if (firstTab || selected || onlyOne || !previousSelected) {
1326 p->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1327 p->drawPoint(x1 + 1, y1 + 1);
1331 int beg = y1 + (previousSelected ? 0 : 2);
1332 int end = y2 - (nextSelected ? 0 : 2);
1334 p->drawLine(x1, beg, x1, end);
1337 if (lastTab || selected || onlyOne || !nextSelected) {
1339 p->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1340 p->drawPoint(x1 + 2, y2 - 1);
1342 p->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1343 p->drawPoint(x1 + 1, y2 - 1);
1344 p->drawPoint(x1 + 2, y2);
1347 case QTabBar::RoundedEast: {
1350 y1 += firstTab ? borderThinkness : 0;
1351 y2 -= lastTab ? borderThinkness : 0;
1354 p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window());
1358 p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.window());
1359 p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.window());
1362 if (firstTab || selected || onlyOne || !previousSelected) {
1364 p->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1365 p->drawPoint(x2 - 1, y1 + 1);
1369 int beg = y1 + (previousSelected ? 0 : 2);
1370 int end = y2 - (nextSelected ? 0 : 2);
1372 p->drawLine(x2, beg, x2, end);
1374 p->drawLine(x2 - 1, beg, x2 - 1, end);
1377 if (lastTab || selected || onlyOne || !nextSelected) {
1379 p->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1380 p->drawPoint(x2 - 1, y2 - 1);
1382 p->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1389 case CE_ToolBoxTabShape:
1390 qDrawShadePanel(p, opt->rect, opt->palette,
1391 opt->state & (State_Sunken | State_On), 1,
1392 &opt->palette.brush(QPalette::Button));
1394#if QT_CONFIG(splitter)
1396 p->eraseRect(opt->rect);
1399#if QT_CONFIG(scrollbar)
1400 case CE_ScrollBarSubLine:
1401 case CE_ScrollBarAddLine: {
1402 if ((opt->state & State_Sunken)) {
1403 p->setPen(opt->palette.dark().color());
1404 p->setBrush(opt->palette.brush(QPalette::Button));
1405 p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
1407 QStyleOption buttonOpt = *opt;
1408 if (!(buttonOpt.state & State_Sunken))
1409 buttonOpt.state |= State_Raised;
1410 QPalette pal(opt->palette);
1411 pal.setColor(QPalette::Button, opt->palette.light().color());
1412 pal.setColor(QPalette::Light, opt->palette.button().color());
1413 qDrawWinButton(p, opt->rect, pal, opt->state & (State_Sunken | State_On),
1414 &opt->palette.brush(QPalette::Button));
1416 PrimitiveElement arrow;
1417 if (opt->state & State_Horizontal) {
1418 if (ce == CE_ScrollBarAddLine)
1419 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1421 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1423 if (ce == CE_ScrollBarAddLine)
1424 arrow = PE_IndicatorArrowDown;
1426 arrow = PE_IndicatorArrowUp;
1428 QStyleOption arrowOpt = *opt;
1429 arrowOpt.rect = opt->rect.adjusted(4, 4, -4, -4);
1430 proxy()->drawPrimitive(arrow, &arrowOpt, p, widget);
1432 case CE_ScrollBarAddPage:
1433 case CE_ScrollBarSubPage: {
1435 QBrush bg = p->background();
1436 Qt::BGMode bg_mode = p->backgroundMode();
1437 p->setPen(Qt::NoPen);
1438 p->setBackgroundMode(Qt::OpaqueMode);
1440 if (opt->state & State_Sunken) {
1441 br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern);
1442 p->setBackground(opt->palette.dark().color());
1445 const QBrush paletteBrush = opt->palette.brush(QPalette::Light);
1446 if (paletteBrush.style() == Qt::TexturePattern) {
1447 if (qHasPixmapTexture(paletteBrush))
1448 br = QBrush(paletteBrush.texture());
1450 br = QBrush(paletteBrush.textureImage());
1452 br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1453 p->setBackground(opt->palette.window().color());
1456 p->drawRect(opt->rect);
1457 p->setBackground(bg);
1458 p->setBackgroundMode(bg_mode);
1460 case CE_ScrollBarSlider:
1461 if (!(opt->state & State_Enabled)) {
1463 const QBrush paletteBrush = opt->palette.brush(QPalette::Light);
1464 if (paletteBrush.style() == Qt::TexturePattern) {
1465 if (qHasPixmapTexture(paletteBrush))
1466 br = QBrush(paletteBrush.texture());
1468 br = QBrush(paletteBrush.textureImage());
1470 br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1471 p->setPen(Qt::NoPen);
1473 p->setBackgroundMode(Qt::OpaqueMode);
1474 p->drawRect(opt->rect);
1476 QStyleOptionButton buttonOpt;
1477 buttonOpt.QStyleOption::operator=(*opt);
1478 buttonOpt.state = State_Enabled | State_Raised;
1480 QPalette pal(opt->palette);
1481 pal.setColor(QPalette::Button, opt->palette.light().color());
1482 pal.setColor(QPalette::Light, opt->palette.button().color());
1483 qDrawWinButton(p, opt->rect, pal,
false, &opt->palette.brush(QPalette::Button));
1487 case CE_HeaderSection: {
1489 if (opt->state & State_On)
1490 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1492 fill = opt->palette.brush(QPalette::Button);
1494 if (opt->state & (State_Raised | State_Sunken)) {
1495 qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill);
1497 p->fillRect(opt->rect, fill);
1500#if QT_CONFIG(toolbar)
1502 if (
const QStyleOptionToolBar *toolbar = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)) {
1504 if (!(widget && qobject_cast<
const QMainWindow*> (widget->parentWidget())))
1507 QRect rect = opt->rect;
1508 bool paintLeftBorder =
true;
1509 bool paintRightBorder =
true;
1510 bool paintBottomBorder =
true;
1512 switch (toolbar->toolBarArea){
1513 case Qt::BottomToolBarArea :
1514 switch(toolbar->positionOfLine){
1515 case QStyleOptionToolBar::Beginning:
1516 case QStyleOptionToolBar::OnlyOne:
1517 paintBottomBorder =
false;
1523 case Qt::TopToolBarArea :
1524 switch(toolbar->positionWithinLine){
1525 case QStyleOptionToolBar::Beginning:
1526 paintLeftBorder =
false;
1528 case QStyleOptionToolBar::End:
1529 paintRightBorder =
false;
1531 case QStyleOptionToolBar::OnlyOne:
1532 paintRightBorder =
false;
1533 paintLeftBorder =
false;
1538 if (opt->direction == Qt::RightToLeft)
1539 std::swap(paintLeftBorder, paintRightBorder);
1541 case Qt::RightToolBarArea :
1542 switch (toolbar->positionOfLine){
1543 case QStyleOptionToolBar::Beginning:
1544 case QStyleOptionToolBar::OnlyOne:
1545 paintRightBorder =
false;
1551 case Qt::LeftToolBarArea :
1552 switch (toolbar->positionOfLine){
1553 case QStyleOptionToolBar::Beginning:
1554 case QStyleOptionToolBar::OnlyOne:
1555 paintLeftBorder =
false;
1567 p->setPen(opt->palette.light().color());
1568 p->drawLine(rect.topLeft(), rect.topRight());
1570 if (paintLeftBorder){
1571 p->setPen(opt->palette.light().color());
1572 p->drawLine(rect.topLeft(), rect.bottomLeft());
1575 if (paintRightBorder){
1576 p->setPen(opt->palette.dark().color());
1577 p->drawLine(rect.topRight(), rect.bottomRight());
1580 if (paintBottomBorder){
1581 p->setPen(opt->palette.dark().color());
1582 p->drawLine(rect.bottomLeft(), rect.bottomRight());
1590 case CE_ProgressBarContents:
1591 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1592 QRect rect = pb->rect;
1593 if (!rect.isValid())
1596 const bool vertical = !(pb->state & QStyle::State_Horizontal);
1597 const bool inverted = pb->invertedAppearance;
1601 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width());
1603 m.translate(0, -(rect.height() + rect.y()*2));
1605 QPalette pal2 = pb->palette;
1607 if (pal2.highlight() == pal2.window())
1608 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
1609 QPalette::Highlight));
1610 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
1613 int w = rect.width();
1614 Q_D(
const QWindowsStyle);
1615 if (pb->minimum == 0 && pb->maximum == 0) {
1616 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
1617 QStyleOptionProgressBar pbBits = *pb;
1618 Q_ASSERT(unit_width >0);
1621 pbBits.palette = pal2;
1624 int chunkCount = w / unit_width + 1;
1625#if QT_CONFIG(animation)
1626 if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject)))
1627 step = (animation->animationStep() / 3) % chunkCount;
1629 d->startAnimation(
new QProgressStyleAnimation(d->animationFps, opt->styleObject));
1633 int chunksInRow = 5;
1634 int myY = pbBits.rect.y();
1635 int myHeight = pbBits.rect.height();
1636 int chunksToDraw = chunksInRow;
1638 if (step > chunkCount - 5)chunksToDraw = (chunkCount - step);
1640 p->setClipRect(m.mapRect(QRectF(rect)).toRect());
1642 int x0 = reverse ? rect.left() + rect.width() - unit_width*(step) - unit_width : rect.left() + unit_width * step;
1645 for (
int i = 0; i < chunksToDraw ; ++i) {
1646 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1647 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1648 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1649 x += reverse ? -unit_width : unit_width;
1652 if ( step > chunkCount-5){
1653 x0 = reverse ? rect.left() + rect.width() - unit_width : rect.left() ;
1655 int chunksToDraw = step - (chunkCount - chunksInRow);
1656 for (
int i = 0; i < chunksToDraw ; ++i) {
1657 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1658 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1659 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1660 x += reverse ? -unit_width : unit_width;
1666#if QT_CONFIG(animation)
1667 d->stopAnimation(opt->styleObject);
1669 QCommonStyle::drawControl(ce, opt, p, widget);
1674#if QT_CONFIG(dockwidget)
1675 case CE_DockWidgetTitle:
1677 if (
const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(opt)) {
1678 Q_D(
const QWindowsStyle);
1680 const bool verticalTitleBar = dwOpt->verticalTitleBar;
1682 QRect rect = dwOpt->rect;
1685 if (verticalTitleBar) {
1689 p->translate(r.left(), r.top() + r.width());
1691 p->translate(-r.left(), -r.top());
1694 bool floating =
false;
1695 bool active = dwOpt->state & State_Active;
1696 QColor inactiveCaptionTextColor = d->inactiveCaptionText;
1697 if (dwOpt->movable) {
1701 if (opt->state & QStyle::State_Window) {
1704 left = d->activeCaptionColor;
1705 right = d->activeGradientCaptionColor;
1707 left = d->inactiveCaptionColor;
1708 right = d->inactiveGradientCaptionColor;
1710 QBrush fillBrush(left);
1711 if (left != right) {
1712 QPoint p1(r.x(), r.top() + r.height()/2);
1713 QPoint p2(rect.right(), r.top() + r.height()/2);
1714 QLinearGradient lg(p1, p2);
1715 lg.setColorAt(0, left);
1716 lg.setColorAt(1, right);
1719 p->fillRect(r.adjusted(0, 0, 0, -3), fillBrush);
1722 if (!dwOpt->title.isEmpty()) {
1723 QFont oldFont = p->font();
1725 QFont font = oldFont;
1729 QPalette palette = dwOpt->palette;
1730 palette.setColor(QPalette::Window, inactiveCaptionTextColor);
1731 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, opt, widget);
1732 if (verticalTitleBar) {
1733 titleRect = QRect(r.left() + rect.bottom()
1734 - titleRect.bottom(),
1735 r.top() + titleRect.left() - rect.left(),
1736 titleRect.height(), titleRect.width());
1738 proxy()->drawItemText(p, titleRect,
1739 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, palette,
1740 dwOpt->state & State_Enabled, dwOpt->title,
1741 floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
1742 p->setFont(oldFont);
1744 if (verticalTitleBar)
1749#if QT_CONFIG(combobox)
1750 case CE_ComboBoxLabel:
1751 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
1752 if (cb->state & State_HasFocus) {
1753 p->setPen(cb->palette.highlightedText().color());
1754 p->setBackground(cb->palette.highlight());
1756 p->setPen(cb->palette.text().color());
1757 p->setBackground(cb->palette.window());
1760 QCommonStyle::drawControl(ce, opt, p, widget);
1764 QCommonStyle::drawControl(ce, opt, p, widget);
1769QRect QWindowsStyle::subElementRect(SubElement sr,
const QStyleOption *opt,
const QWidget *w)
const
1773 case SE_SliderFocusRect:
1774 case SE_ToolBoxTabContents:
1775 r = visualRect(opt->direction, opt->rect, opt->rect);
1777 case SE_DockWidgetTitleBarText: {
1778 r = QCommonStyle::subElementRect(sr, opt, w);
1779 const QStyleOptionDockWidget *dwOpt
1780 = qstyleoption_cast<
const QStyleOptionDockWidget*>(opt);
1781 const bool verticalTitleBar = dwOpt && dwOpt->verticalTitleBar;
1782 int m = proxy()->pixelMetric(PM_DockWidgetTitleMargin, opt, w);
1783 if (verticalTitleBar) {
1784 r.adjust(0, 0, 0, -m);
1786 if (opt->direction == Qt::LeftToRight)
1787 r.adjust(m, 0, 0, 0);
1789 r.adjust(0, 0, -m, 0);
1793 case SE_ProgressBarContents:
1794 r = QCommonStyle::subElementRect(SE_ProgressBarGroove, opt, w);
1795 r.adjust(3, 3, -3, -3);
1798 r = QCommonStyle::subElementRect(sr, opt, w);
1805void QWindowsStyle::drawComplexControl(ComplexControl cc,
const QStyleOptionComplex *opt,
1806 QPainter *p,
const QWidget *widget)
const
1809#if QT_CONFIG(slider)
1811 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
1812 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
1813 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
1814 int ticks = slider->tickPosition;
1815 QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
1816 QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
1818 if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
1819 int mid = thickness / 2;
1821 if (ticks & QSlider::TicksAbove)
1823 if (ticks & QSlider::TicksBelow)
1826 p->setPen(slider->palette.shadow().color());
1827 if (slider->orientation == Qt::Horizontal) {
1828 qDrawWinPanel(p, groove.x(), groove.y() + mid - 2,
1829 groove.width(), 4, slider->palette,
true);
1830 p->drawLine(groove.x() + 1, groove.y() + mid - 1,
1831 groove.x() + groove.width() - 3, groove.y() + mid - 1);
1833 qDrawWinPanel(p, groove.x() + mid - 2, groove.y(),
1834 4, groove.height(), slider->palette,
true);
1835 p->drawLine(groove.x() + mid - 1, groove.y() + 1,
1836 groove.x() + mid - 1, groove.y() + groove.height() - 3);
1840 if (slider->subControls & SC_SliderTickmarks) {
1841 QStyleOptionSlider tmpSlider = *slider;
1842 tmpSlider.subControls = SC_SliderTickmarks;
1843 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
1846 if (slider->subControls & SC_SliderHandle) {
1856 const QColor c0 = slider->palette.shadow().color();
1857 const QColor c1 = slider->palette.dark().color();
1859 const QColor c3 = slider->palette.midlight().color();
1860 const QColor c4 = slider->palette.light().color();
1863 if (slider->state & State_Enabled) {
1864 handleBrush = slider->palette.color(QPalette::Button);
1866 handleBrush = QBrush(slider->palette.color(QPalette::Button),
1871 int x = handle.x(), y = handle.y(),
1872 wi = handle.width(), he = handle.height();
1879 Qt::Orientation orient = slider->orientation;
1880 bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
1881 bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
1883 if (slider->state & State_HasFocus) {
1884 QStyleOptionFocusRect fropt;
1885 fropt.QStyleOption::operator=(*slider);
1886 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
1887 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1890 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
1891 Qt::BGMode oldMode = p->backgroundMode();
1892 p->setBackgroundMode(Qt::OpaqueMode);
1893 qDrawWinButton(p, QRect(x, y, wi, he), slider->palette,
false,
1895 p->setBackgroundMode(oldMode);
1899 QSliderDirection dir;
1901 if (orient == Qt::Horizontal)
1902 dir = tickAbove ? SlUp : SlDown;
1904 dir = tickAbove ? SlLeft : SlRight;
1906 std::array<QPoint, 5> points;
1911 d = (wi + 1) / 2 - 1;
1912 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2),
1913 QPoint(x2, y1), QPoint(x1 + d, y1 - d)};
1917 d = (wi + 1) / 2 - 1;
1918 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x1 + d, y2 + d),
1919 QPoint(x2, y2), QPoint(x2, y1)};
1922 d = (he + 1) / 2 - 1;
1924 points = {QPoint(x1, y1), QPoint(x1 - d, y1 + d), QPoint(x1,y2),
1925 QPoint(x2, y2), QPoint(x2, y1)};
1928 d = (he + 1) / 2 - 1;
1930 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2),
1931 QPoint(x2 + d, y1 + d), QPoint(x2, y1)};
1935 QBrush oldBrush = p->brush();
1936 p->setPen(Qt::NoPen);
1937 p->setBrush(handleBrush);
1938 Qt::BGMode oldMode = p->backgroundMode();
1939 p->setBackgroundMode(Qt::OpaqueMode);
1940 p->drawRect(x1, y1, x2-x1+1, y2-y1+1);
1941 p->drawPolygon(points.data(),
static_cast<
int>(points.size()));
1942 p->setBrush(oldBrush);
1943 p->setBackgroundMode(oldMode);
1947 p->drawLine(x1, y1, x2, y1);
1949 p->drawLine(x1, y1+1, x2, y1+1);
1951 if (dir != SlLeft) {
1953 p->drawLine(x1+1, y1+1, x1+1, y2);
1955 p->drawLine(x1, y1, x1, y2);
1957 if (dir != SlRight) {
1959 p->drawLine(x2, y1, x2, y2);
1961 p->drawLine(x2-1, y1+1, x2-1, y2-1);
1963 if (dir != SlDown) {
1965 p->drawLine(x1, y2, x2, y2);
1967 p->drawLine(x1+1, y2-1, x2-1, y2-1);
1973 p->drawLine(x1, y1, x1+d, y1-d);
1976 p->drawLine(x2, y1, x2-d, y1-d);
1979 p->drawLine(x1+1, y1, x1+1+d, y1-d);
1981 p->drawLine(x2-1, y1, x2-1-d, y1-d);
1985 p->drawLine(x1, y2, x1+d, y2+d);
1988 p->drawLine(x2, y2, x2-d, y2+d);
1991 p->drawLine(x1+1, y2, x1+1+d, y2+d);
1993 p->drawLine(x2-1, y2, x2-1-d, y2+d);
1997 p->drawLine(x1, y1, x1-d, y1+d);
2000 p->drawLine(x1, y2, x1-d, y2-d);
2003 p->drawLine(x1, y1+1, x1-d, y1+1+d);
2005 p->drawLine(x1, y2-1, x1-d, y2-1-d);
2009 p->drawLine(x2, y1, x2+d, y1+d);
2012 p->drawLine(x2, y2, x2+d, y2-d);
2015 p->drawLine(x2, y1+1, x2+d, y1+1+d);
2017 p->drawLine(x2, y2-1, x2+d, y2-1-d);
2024#if QT_CONFIG(scrollbar)
2026 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
2027 QStyleOptionSlider newScrollbar = *scrollbar;
2028 if (scrollbar->minimum == scrollbar->maximum)
2029 newScrollbar.state &= ~State_Enabled;
2030 QCommonStyle::drawComplexControl(cc, &newScrollbar, p, widget);
2034#if QT_CONFIG(combobox)
2036 if (
const QStyleOptionComboBox *cmb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
2037 QBrush editBrush = cmb->palette.brush(QPalette::Button);
2038 if ((cmb->subControls & SC_ComboBoxFrame)) {
2040 QPalette shadePal = opt->palette;
2041 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2042 qDrawWinPanel(p, opt->rect, shadePal,
true, &editBrush);
2045 p->fillRect(opt->rect, editBrush);
2048 if (cmb->subControls & SC_ComboBoxArrow) {
2049 State flags = State_None;
2051 QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
2052 bool sunkenArrow = cmb->activeSubControls == SC_ComboBoxArrow
2053 && cmb->state & State_Sunken;
2055 p->setPen(cmb->palette.dark().color());
2056 p->setBrush(cmb->palette.brush(QPalette::Button));
2057 p->drawRect(ar.adjusted(0,0,-1,-1));
2060 QPalette pal(cmb->palette);
2061 pal.setColor(QPalette::Button, cmb->palette.light().color());
2062 pal.setColor(QPalette::Light, cmb->palette.button().color());
2063 qDrawWinButton(p, ar, pal,
false,
2064 &cmb->palette.brush(QPalette::Button));
2067 ar.adjust(2, 2, -2, -2);
2068 if (opt->state & State_Enabled)
2069 flags |= State_Enabled;
2070 if (opt->state & State_HasFocus)
2071 flags |= State_HasFocus;
2074 flags |= State_Sunken;
2075 QStyleOption arrowOpt = *cmb;
2076 arrowOpt.rect = ar.adjusted(1, 1, -1, -1);
2077 arrowOpt.state = flags;
2078 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
2081 if (cmb->subControls & SC_ComboBoxEditField) {
2082 QRect re = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
2083 if (cmb->state & State_HasFocus && !cmb->editable)
2084 p->fillRect(re.x(), re.y(), re.width(), re.height(),
2085 cmb->palette.brush(QPalette::Highlight));
2087 if (cmb->state & State_HasFocus) {
2088 p->setPen(cmb->palette.highlightedText().color());
2089 p->setBackground(cmb->palette.highlight());
2092 p->setPen(cmb->palette.text().color());
2093 p->setBackground(cmb->palette.window());
2096 if (cmb->state & State_HasFocus && !cmb->editable) {
2097 QStyleOptionFocusRect focus;
2098 focus.QStyleOption::operator=(*cmb);
2099 focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
2100 focus.state |= State_FocusAtBorder;
2101 focus.backgroundColor = cmb->palette.highlight().color();
2102 proxy()->drawPrimitive(PE_FrameFocusRect, &focus, p, widget);
2108#if QT_CONFIG(spinbox)
2110 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
2111 QStyleOptionSpinBox copy = *sb;
2112 PrimitiveElement pe;
2113 bool enabled = opt->state & State_Enabled;
2114 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
2115 QBrush editBrush = sb->palette.brush(QPalette::Base);
2116 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
2117 QPalette shadePal = sb->palette;
2118 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2119 qDrawWinPanel(p, r, shadePal,
true, &editBrush);
2122 QPalette shadePal(opt->palette);
2123 shadePal.setColor(QPalette::Button, opt->palette.light().color());
2124 shadePal.setColor(QPalette::Light, opt->palette.button().color());
2126 if (sb->subControls & SC_SpinBoxUp) {
2127 copy.subControls = SC_SpinBoxUp;
2128 QPalette pal2 = sb->palette;
2129 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
2130 pal2.setCurrentColorGroup(QPalette::Disabled);
2131 copy.state &= ~State_Enabled;
2134 copy.palette = pal2;
2136 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
2137 copy.state |= State_On;
2138 copy.state |= State_Sunken;
2140 copy.state |= State_Raised;
2141 copy.state &= ~State_Sunken;
2143 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
2144 : PE_IndicatorSpinUp);
2146 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
2147 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2148 ©.palette.brush(QPalette::Button));
2149 copy.rect.adjust(4, 1, -5, -1);
2150 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled))
2151 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2153 QStyleOptionSpinBox lightCopy = copy;
2154 lightCopy.rect.adjust(1, 1, 1, 1);
2155 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2156 proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2158 proxy()->drawPrimitive(pe, ©, p, widget);
2161 if (sb->subControls & SC_SpinBoxDown) {
2162 copy.subControls = SC_SpinBoxDown;
2163 copy.state = sb->state;
2164 QPalette pal2 = sb->palette;
2165 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
2166 pal2.setCurrentColorGroup(QPalette::Disabled);
2167 copy.state &= ~State_Enabled;
2169 copy.palette = pal2;
2171 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
2172 copy.state |= State_On;
2173 copy.state |= State_Sunken;
2175 copy.state |= State_Raised;
2176 copy.state &= ~State_Sunken;
2178 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
2179 : PE_IndicatorSpinDown);
2181 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
2182 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2183 ©.palette.brush(QPalette::Button));
2184 copy.rect.adjust(4, 0, -5, -1);
2185 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled))
2186 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2188 QStyleOptionSpinBox lightCopy = copy;
2189 lightCopy.rect.adjust(1, 1, 1, 1);
2190 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2191 proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2193 proxy()->drawPrimitive(pe, ©, p, widget);
2200 QCommonStyle::drawComplexControl(cc, opt, p, widget);
2205QSize QWindowsStyle::sizeFromContents(ContentsType ct,
const QStyleOption *opt,
2206 const QSize &csz,
const QWidget *widget)
const
2211 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2212 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2216 if (btn->features & QStyleOptionButton::AutoDefaultButton)
2217 defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2218 const qreal dpi = QStyleHelper::dpi(opt);
2219 int minwidth =
int(QStyleHelper::dpiScaled(75, dpi));
2220 int minheight =
int(QStyleHelper::dpiScaled(23, dpi));
2222 if (w < minwidth + defwidth && !btn->text.isEmpty())
2223 w = minwidth + defwidth;
2224 if (h < minheight + defwidth)
2225 h = minheight + defwidth;
2232 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
2234 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2236 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
2237 sz = QSize(10, QWindowsStylePrivate::windowsSepHeight);
2239 else if (mi->icon.isNull()) {
2240 sz.setHeight(sz.height() - 2);
2244 if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull()) {
2245 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
2246 sz.setHeight(qMax(sz.height(),
2247 mi->icon.actualSize(QSize(iconExtent, iconExtent)).height()
2248 + 2 * QWindowsStylePrivate::windowsItemFrame));
2250 int maxpmw = mi->maxIconWidth;
2251 int tabSpacing = 20;
2252 if (mi->text.contains(u'\t'))
2254 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
2255 w += 2 * QWindowsStylePrivate::windowsArrowHMargin;
2256 else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
2259 QFontMetrics fm(mi->font);
2260 QFont fontBold = mi->font;
2261 fontBold.setBold(
true);
2262 QFontMetrics fmBold(fontBold);
2263 w += fmBold.horizontalAdvance(mi->text) - fm.horizontalAdvance(mi->text);
2266 int checkcol = qMax<
int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth);
2268 w +=
int(QWindowsStylePrivate::windowsRightBorder) + 10;
2273#if QT_CONFIG(menubar)
2274 case CT_MenuBarItem:
2276 sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2);
2280#if QT_CONFIG(toolbutton)
2281 if (qstyleoption_cast<
const QStyleOptionToolButton *>(opt))
2282 return sz += QSize(7, 6);
2287 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2293
2294
2295QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon,
const QStyleOption *option,
2296 const QWidget *widget)
const
2298 return QCommonStyle::standardIcon(standardIcon, option, widget);
2305#include "moc_qwindowsstyle_p.cpp"