summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2009-09-14 10:59:39 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2009-09-14 11:07:23 (GMT)
commitf44fe888ee82b9e04879fb353d8f5f29fb4d5229 (patch)
treec5f407e3e39b52d0cd251d732895a6bb57e1901b
parent2a46755b307adde38f7075f2add01224fd00846b (diff)
downloadQt-f44fe888ee82b9e04879fb353d8f5f29fb4d5229.zip
Qt-f44fe888ee82b9e04879fb353d8f5f29fb4d5229.tar.gz
Qt-f44fe888ee82b9e04879fb353d8f5f29fb4d5229.tar.bz2
Fix RTL text alignment in QComboBox items with SH_ComboBox_Popup
Change 93ba0035f4eadfaf7217d95f18a442d418a064b8 removed truncation of a listview item's bounding rect to the viewport as documented in the commit log. An unwanted result was that the style option passed to the item delegates would sometimes contain a rectangle which was larger than the delegated area. The direct result was that a QComboBox drawn with a style with the SH_Combobox_Popup style hint in an RTL language would align its item text to the right edge of a rectangle which was wider than the popup menu, and thus only part of the text would be visible. Task-number: 260974 Reviewed-by: Olivier
-rw-r--r--src/gui/itemviews/qlistview.cpp6
-rw-r--r--tests/auto/qcombobox/tst_qcombobox.cpp36
2 files changed, 42 insertions, 0 deletions
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp
index cbb54d8..a4cebe3 100644
--- a/src/gui/itemviews/qlistview.cpp
+++ b/src/gui/itemviews/qlistview.cpp
@@ -965,6 +965,12 @@ void QListView::paintEvent(QPaintEvent *e)
for (QVector<QModelIndex>::const_iterator it = toBeRendered.constBegin(); it != end; ++it) {
Q_ASSERT((*it).isValid());
option.rect = visualRect(*it);
+
+ if (flow() == TopToBottom)
+ option.rect.setWidth(qMin(viewport()->size().width(), option.rect.width()));
+ else
+ option.rect.setHeight(qMin(viewport()->size().height(), option.rect.height()));
+
option.state = state;
if (selections && selections->isSelected(*it))
option.state |= QStyle::State_Selected;
diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp
index e75b9cd..810be04 100644
--- a/tests/auto/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/qcombobox/tst_qcombobox.cpp
@@ -147,6 +147,7 @@ private slots:
void task253944_itemDelegateIsReset();
void subControlRectsWithOffset_data();
void subControlRectsWithOffset();
+ void task260974_menuItemRectangleForComboBoxPopup();
protected slots:
void onEditTextChanged( const QString &newString );
@@ -2339,5 +2340,40 @@ void tst_QComboBox::subControlRectsWithOffset()
}
+void tst_QComboBox::task260974_menuItemRectangleForComboBoxPopup()
+{
+ class TestStyle: public QWindowsStyle
+ {
+ public:
+ int styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *ret) const
+ {
+ if (hint == SH_ComboBox_Popup) return 1;
+ else return QCommonStyle::styleHint(hint, option, widget, ret);
+ }
+
+ void drawControl(ControlElement element, const QStyleOption *option, QPainter *, const QWidget *) const
+ {
+ if (element == CE_MenuItem)
+ discoveredRect = option->rect;
+ }
+
+ mutable QRect discoveredRect;
+ } style;
+
+
+ {
+ QComboBox comboBox;
+ comboBox.setStyle(&style);
+ comboBox.addItem("Item 1");
+
+ comboBox.show();
+ QTest::qWait(100);
+ comboBox.showPopup();
+ QTest::qWait(100);
+
+ QVERIFY(style.discoveredRect.width() <= comboBox.width());
+ }
+}
+
QTEST_MAIN(tst_QComboBox)
#include "tst_qcombobox.moc"