summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/styles/qmacstyle_mac.mm13
-rw-r--r--tests/auto/qcombobox/tst_qcombobox.cpp50
2 files changed, 60 insertions, 3 deletions
diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm
index 389ee85..4696ee1 100644
--- a/src/gui/styles/qmacstyle_mac.mm
+++ b/src/gui/styles/qmacstyle_mac.mm
@@ -5495,16 +5495,23 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op
case SC_ComboBoxArrow:{
ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi);
ret.setX(ret.x() + ret.width());
- ret.setWidth(combo->rect.width() - ret.width() - ret.x());
+ ret.setWidth(combo->rect.right() - ret.right());
break; }
case SC_ComboBoxListBoxPopup:{
if (combo->editable) {
HIRect inner = QMacStylePrivate::comboboxInnerBounds(qt_hirectForQRect(combo->rect), bdi.kind);
QRect editRect = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi);
- ret.adjust(qRound(inner.origin.x), 0, qRound(inner.origin.x + inner.size.width), editRect.y() + editRect.height() + 2);
+ const int comboTop = combo->rect.top();
+ ret = QRect(qRound(inner.origin.x),
+ comboTop,
+ qRound(inner.origin.x - combo->rect.left() + inner.size.width),
+ editRect.bottom() - comboTop + 2);
} else {
QRect editRect = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi);
- ret.adjust(4 - 11, 1, editRect.width() + 10 + 11, 1);
+ ret = QRect(combo->rect.x() + 4 - 11,
+ combo->rect.y() + 1,
+ editRect.width() + 10 + 11,
+ 1);
}
break; }
default:
diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp
index 204a2fa..52c6c02 100644
--- a/tests/auto/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/qcombobox/tst_qcombobox.cpp
@@ -145,6 +145,8 @@ private slots:
void setItemDelegate();
void task253944_itemDelegateIsReset();
void paintingWithOffset();
+ void subControlRectsWithOffset_data();
+ void subControlRectsWithOffset();
protected slots:
void onEditTextChanged( const QString &newString );
@@ -2276,5 +2278,53 @@ void tst_QComboBox::paintingWithOffset()
QCOMPARE(noOffsetImage, translatedOffsetImage);
}
+void tst_QComboBox::subControlRectsWithOffset_data()
+{
+ QTest::addColumn<bool>("editable");
+
+ QTest::newRow("editable = true") << true;
+ QTest::newRow("editable = false") << false;
+}
+
+void tst_QComboBox::subControlRectsWithOffset()
+{
+ // The sub control rect relative position should not depends
+ // on the position of the combobox
+
+ class FriendlyCombo : public QComboBox {
+ public:
+ void styleOption(QStyleOptionComboBox *optCombo) {
+ initStyleOption(optCombo);
+ }
+ } combo;
+ QStyleOptionComboBox optCombo;
+ combo.styleOption(&optCombo);
+
+
+ const QRect rectAtOrigin(0, 0, 80, 30);
+ const QPoint offset(25, 50);
+ const QRect rectWithOffset = rectAtOrigin.translated(offset);
+
+ QStyle *style = combo.style();
+
+ QFETCH(bool, editable);
+ optCombo.editable = editable;
+
+ optCombo.rect = rectAtOrigin;
+ QRect editFieldRect = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxEditField, 0);
+ QRect arrowRect = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxArrow, 0);
+ QRect listboxRect = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxListBoxPopup, 0);
+
+ optCombo.rect = rectWithOffset;
+ QRect editFieldRectWithOffset = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxEditField, 0);
+ QRect arrowRectWithOffset = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxArrow, 0);
+ QRect listboxRectWithOffset = style->subControlRect(QStyle::CC_ComboBox, &optCombo, QStyle::SC_ComboBoxListBoxPopup, 0);
+
+ QCOMPARE(editFieldRect, editFieldRectWithOffset.translated(-offset));
+ QCOMPARE(arrowRect, arrowRectWithOffset.translated(-offset));
+ QCOMPARE(listboxRect, listboxRectWithOffset.translated(-offset));
+
+}
+
QTEST_MAIN(tst_QComboBox)
#include "tst_qcombobox.moc"