summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-05-06 15:41:56 +0200
committerAndy Shaw <andy.shaw@qt.io>2020-05-15 05:00:10 +0200
commitf468f76455c91cf1c5b477ab9348337522b4d9aa (patch)
tree26f18ae1276d2867e2692b434cf3cb4e2449f58a /src
parent6028e16b8693c8c7403fd4e5341c52beb33e5613 (diff)
Add an option to set the alignment of the text in QComboBox
Change-Id: Ic9dca8864643302b2b3ff7dbd86260efdb0ab1d5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/styles/qcommonstyle.cpp2
-rw-r--r--src/widgets/styles/qfusionstyle.cpp2
-rw-r--r--src/widgets/styles/qstyleoption.cpp9
-rw-r--r--src/widgets/styles/qstyleoption.h3
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp2
-rw-r--r--src/widgets/widgets/qcombobox.cpp6
6 files changed, 18 insertions, 6 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index a52e14eaf9..cc7af2ccc8 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -2222,7 +2222,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
}
if (!cb->currentText.isEmpty() && !cb->editable) {
proxy()->drawItemText(p, editRect.adjusted(1, 0, -1, 0),
- visualAlignment(cb->direction, Qt::AlignLeft | Qt::AlignVCenter),
+ visualAlignment(cb->direction, cb->textAlignment),
cb->palette, cb->state & State_Enabled, cb->currentText);
}
p->restore();
diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp
index b9abedd626..dfd979cf7d 100644
--- a/src/widgets/styles/qfusionstyle.cpp
+++ b/src/widgets/styles/qfusionstyle.cpp
@@ -1059,7 +1059,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
}
if (!cb->currentText.isEmpty() && !cb->editable) {
proxy()->drawItemText(painter, editRect.adjusted(1, 0, -1, 0),
- visualAlignment(cb->direction, Qt::AlignLeft | Qt::AlignVCenter),
+ visualAlignment(cb->direction, cb->textAlignment),
cb->palette, cb->state & State_Enabled, cb->currentText,
cb->editable ? QPalette::Text : QPalette::ButtonText);
}
diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp
index 122775879f..3194f5b941 100644
--- a/src/widgets/styles/qstyleoption.cpp
+++ b/src/widgets/styles/qstyleoption.cpp
@@ -2611,7 +2611,7 @@ QStyleOptionComboBox::QStyleOptionComboBox(int version)
This enum is used to hold information about the version of the style option, and
is defined for each QStyleOption subclass.
- \value Version 1
+ \value Version 2
The version is used by QStyleOption subclasses to implement
extensions without breaking compatibility. If you use
@@ -2673,6 +2673,13 @@ QStyleOptionComboBox::QStyleOptionComboBox(int version)
*/
/*!
+ \variable QStyleOptionGroupBox::textAlignment
+ \brief the alignment of the current text in the combo box
+
+ The default value is Qt::AlignLeft | Qt::AlignVCenter.
+*/
+
+/*!
\class QStyleOptionToolBox
\brief The QStyleOptionToolBox class is used to describe the
parameters needed for drawing a tool box.
diff --git a/src/widgets/styles/qstyleoption.h b/src/widgets/styles/qstyleoption.h
index 52893ebd83..7f3fc4b49e 100644
--- a/src/widgets/styles/qstyleoption.h
+++ b/src/widgets/styles/qstyleoption.h
@@ -609,7 +609,7 @@ class Q_WIDGETS_EXPORT QStyleOptionComboBox : public QStyleOptionComplex
{
public:
enum StyleOptionType { Type = SO_ComboBox };
- enum StyleOptionVersion { Version = 1 };
+ enum StyleOptionVersion { Version = 2 };
bool editable;
QRect popupRect;
@@ -617,6 +617,7 @@ public:
QString currentText;
QIcon currentIcon;
QSize iconSize;
+ Qt::Alignment textAlignment = Qt::AlignLeft | Qt::AlignVCenter;
QStyleOptionComboBox();
QStyleOptionComboBox(const QStyleOptionComboBox &other) : QStyleOptionComplex(Version, Type) { *this = other; }
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 32f86e5b5a..13db17fbfb 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -3894,7 +3894,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
if (!cb->currentText.isEmpty() && !cb->editable) {
QPalette styledPalette(cb->palette);
rule.configurePalette(&styledPalette, QPalette::Text, QPalette::Base);
- drawItemText(p, editRect.adjusted(0, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, styledPalette,
+ drawItemText(p, editRect.adjusted(0, 0, 0, 0), cb->textAlignment, styledPalette,
cb->state & State_Enabled, cb->currentText, QPalette::Text);
}
p->restore();
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index a0e04285e9..ba771f7ce9 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -1240,8 +1240,12 @@ void QComboBox::initStyleOption(QStyleOptionComboBox *option) const
option->activeSubControls = d->hoverControl;
}
option->currentText = currentText();
- if (d->currentIndex.isValid())
+ if (d->currentIndex.isValid()) {
option->currentIcon = d->itemIcon(d->currentIndex);
+ QVariant alignment = d->model->data(d->currentIndex, Qt::TextAlignmentRole);
+ if (alignment.isValid())
+ option->textAlignment = static_cast<Qt::Alignment>(alignment.toUInt());
+ }
option->iconSize = iconSize();
if (d->container && d->container->isVisible())
option->state |= QStyle::State_On;