summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Merila <sami.merila@nokia.com>2010-04-14 10:06:28 (GMT)
committerSami Merila <sami.merila@nokia.com>2010-04-14 10:06:28 (GMT)
commit1c5c69b01659acc33bb49ffe4b078848b6a2a9de (patch)
tree85f7812807d29a597b7736181bf3905833b21554
parente4d03c6b56decd63035a7c46498dae2d2a483c09 (diff)
downloadQt-1c5c69b01659acc33bb49ffe4b078848b6a2a9de.zip
Qt-1c5c69b01659acc33bb49ffe4b078848b6a2a9de.tar.gz
Qt-1c5c69b01659acc33bb49ffe4b078848b6a2a9de.tar.bz2
QS60Style: In a very short combobox, text is cut
If QComboBox is very short, it is possible that the combobox text is cut. This is due to two reasons: 1) Style does not take into account text eliding (which should be preferred over clipping) 2) Clipping text rect is done with orginal text rect, before it is adjusted for borders, icons etc. Style is changed that it doesn't use clipping rect and uses text eliding. Task-number: QTBUG-9837 Reviewed-by: Alessandro Portale
-rw-r--r--src/gui/styles/qs60style.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp
index f154b2d..0ebfe39 100644
--- a/src/gui/styles/qs60style.cpp
+++ b/src/gui/styles/qs60style.cpp
@@ -1372,14 +1372,13 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option,
optionComboBox.palette.setColor(QPalette::Inactive, QPalette::WindowText,
optionComboBox.palette.text().color() );
QRect editRect = subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget);
- painter->save();
- painter->setClipRect(editRect);
+ const int frameW = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
if (!comboBox->currentIcon.isNull()) {
- QIcon::Mode mode = comboBox->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
- QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode);
+ const QIcon::Mode mode = comboBox->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
+ const QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode);
QRect iconRect(editRect);
- iconRect.setWidth(comboBox->iconSize.width() + 4);
+ iconRect.setWidth(comboBox->iconSize.width() + frameW);
iconRect = alignedRect(comboBox->direction,
Qt::AlignLeft | Qt::AlignVCenter,
iconRect.size(), editRect);
@@ -1388,17 +1387,19 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option,
drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
if (comboBox->direction == Qt::RightToLeft)
- editRect.translate(-4 - comboBox->iconSize.width(), 0);
+ editRect.setRight(editRect.right() - frameW - comboBox->iconSize.width());
else
- editRect.translate(comboBox->iconSize.width() + 4, 0);
+ editRect.setLeft(comboBox->iconSize.width() + frameW);
}
if (!comboBox->currentText.isEmpty() && !comboBox->editable) {
+ const Qt::TextElideMode elideMode = (comboBox->direction == Qt::LeftToRight) ? Qt::ElideRight : Qt::ElideLeft;
+ const QString text = comboBox->fontMetrics.elidedText(comboBox->currentText, elideMode, editRect.width());
+
QCommonStyle::drawItemText(painter,
editRect.adjusted(QS60StylePrivate::pixelMetric(PM_FrameCornerWidth), 0, -1, 0),
visualAlignment(comboBox->direction, Qt::AlignLeft | Qt::AlignVCenter),
- comboBox->palette, comboBox->state & State_Enabled, comboBox->currentText);
+ comboBox->palette, comboBox->state & State_Enabled, text);
}
- painter->restore();
}
break;
#endif //QT_NO_COMBOBOX