From 5557b6930405c38ba02bf5394de4ff42aa2b6181 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 25 Jan 2019 10:48:34 +0100 Subject: QColorDialog: Remove flag Qt::MSWindowsFixedSizeDialogHint The flag causes issues with High DPI scaling (the OS maintains the size in device pixels when moving across screens). It does not really make a difference (apart from the resize handle appearing) since the dialog uses QLayout::SetFixedSize. Fixes: QTBUG-73232 Change-Id: Iad08427796890582ac05758678d24e3cd707e669 Reviewed-by: Andy Shaw --- src/widgets/dialogs/qcolordialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 93e49466cb..7132bb3297 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -1887,7 +1887,7 @@ bool QColorDialogPrivate::canBeNativeDialog() const } static const Qt::WindowFlags DefaultWindowFlags = - Qt::Dialog | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint + Qt::Dialog | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; /*! -- cgit v1.2.3 From f92ca8323029fe3f935c4410a6fb6a895b40f903 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 21 Jan 2019 10:30:10 +0100 Subject: Don't enable the input method for the QListView in a QInputDialog As the listview in an input dialog is only used for selecting the entry in place of a combobox, then we should prevent the input method from being enabled. This ensures that it does not show an invalid text cursor on devices like iOS and Android. Change-Id: Ifb854e509573ec2d63d4cbcfa61335ae5b251ab5 Reviewed-by: Richard Moe Gustavsen --- src/widgets/dialogs/qinputdialog.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/dialogs/qinputdialog.cpp b/src/widgets/dialogs/qinputdialog.cpp index 5a7d6edddf..3cfe8367e0 100644 --- a/src/widgets/dialogs/qinputdialog.cpp +++ b/src/widgets/dialogs/qinputdialog.cpp @@ -168,6 +168,18 @@ private: } }; +class QInputDialogListView : public QListView +{ +public: + QInputDialogListView(QWidget *parent = 0) : QListView(parent) {} + QVariant inputMethodQuery(Qt::InputMethodQuery query) const override + { + if (query == Qt::ImEnabled) + return false; + return QListView::inputMethodQuery(query); + } +}; + class QInputDialogPrivate : public QDialogPrivate { Q_DECLARE_PUBLIC(QInputDialog) @@ -201,7 +213,7 @@ public: mutable QSpinBox *intSpinBox; mutable QDoubleSpinBox *doubleSpinBox; mutable QComboBox *comboBox; - mutable QListView *listView; + mutable QInputDialogListView *listView; mutable QWidget *inputWidget; mutable QVBoxLayout *mainLayout; QInputDialog::InputDialogOptions opts; @@ -298,8 +310,7 @@ void QInputDialogPrivate::ensureListView() Q_Q(QInputDialog); if (!listView) { ensureComboBox(); - - listView = new QListView(q); + listView = new QInputDialogListView(q); listView->hide(); listView->setEditTriggers(QAbstractItemView::NoEditTriggers); listView->setSelectionMode(QAbstractItemView::SingleSelection); -- cgit v1.2.3 From 3615e8aaa158cc88edf539a2252f96a8c635b4cd Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Tue, 11 Dec 2018 10:32:56 +0100 Subject: Doc: Correct minor link issue in qwidget.cpp Change-Id: I3b69a18c65b75f3e0014a12284904af208ef058d Reviewed-by: Paul Wicking Reviewed-by: Venugopal Shivashankar --- src/widgets/kernel/qwidget.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index c66fc098a1..19599cc008 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -4509,8 +4509,7 @@ void QWidget::setForegroundRole(QPalette::ColorRole role) style, depend on third party APIs to render the content of widgets, and these styles typically do not follow the palette. Because of this, assigning roles to a widget's palette is not guaranteed to change the - appearance of the widget. Instead, you may choose to apply a \l - styleSheet. + appearance of the widget. Instead, you may choose to apply a \l {styleSheet}. \warning Do not use this function in conjunction with \l{Qt Style Sheets}. When using style sheets, the palette of a widget can be customized using -- cgit v1.2.3 From fcba9fa861574f33e1d2e54d8c8d6da8062927cd Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 23 Jan 2019 10:42:12 +0100 Subject: Fix regression in QPlainTextEdit updating It was incorrectly counting a block having more than one line as having changed visibility. Fixes: QTBUG-69310 Change-Id: I502cda1d3e8a4efb1c14122353cc0a4731d8581c Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qplaintextedit.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index d6f6a364a8..57f2dec8f7 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -312,10 +312,11 @@ void QPlainTextDocumentLayout::documentChanged(int from, int charsRemoved, int c QTextBlock block = changeStartBlock; do { block.clearLayout(); - const int lineCount = block.isVisible() ? 1 : 0; - if (block.lineCount() != lineCount) { + if (block.isVisible() + ? (block.lineCount() == 0) + : (block.lineCount() > 0)) { blockVisibilityChanged = true; - block.setLineCount(lineCount); + block.setLineCount(block.isVisible() ? 1 : 0); } if (block == changeEndBlock) break; -- cgit v1.2.3 From 0736e050cb0f82ca445e954e1db631f1dd1de473 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 8 Jan 2019 20:58:26 +0100 Subject: QMenuItem: fix rendering with css styling The rendering of a css styled menu item with icons or checkmark was partially fixed with aa1bc47942e2062dc7fad3e139bb4ceecc74f947 but introduced some other painting regressions, especially in RTL mode. Fix it by syncing the code with fusion and windows style. With this patch a menu text with a check mark but no icon is now aligned exactly the same as a menu text with a icon. Fixes: QTBUG-66380 Fixes: QTBUG-70491 Fixes: QTBUG-72817 Change-Id: I83a95d15eb130e7f72471820b53c3cd5554d9334 Reviewed-by: Nick D'Ademo Reviewed-by: Richard Moe Gustavsen --- src/widgets/styles/qstylesheetstyle.cpp | 36 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 7c1c0ca3d8..79fa20851f 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3705,21 +3705,17 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); QStyleOptionMenuItem newMi = mi; newMi.rect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); - checkableOffset = newMi.rect.width(); + // align with icons if there are some + checkableOffset = std::max(m->maxIconWidth, newMi.rect.width()); if (subSubRule.hasDrawable() || checked) drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w); } - int iconOffset = 0; if (!mi.icon.isNull()) { QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; if (act && !dis) mode = QIcon::Active; - QPixmap pixmap; - if (checked) - pixmap = mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On); - else - pixmap = mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode); + const QPixmap pixmap(mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode, checked ? QIcon::On : QIcon::Off)); const int pixw = pixmap.width() / pixmap.devicePixelRatio(); const int pixh = pixmap.height() / pixmap.devicePixelRatio(); QRenderRule iconRule = renderRule(w, opt, PseudoElement_MenuIcon); @@ -3738,15 +3734,20 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(iconRect.center()); p->drawPixmap(pmr.topLeft(), pixmap); - iconOffset = iconRule.geo->width; } + int textOffset = 0; + // padding overrules it all + if (!subRule.hasBox() || subRule.box()->paddings[LeftEdge] == 0) { + textOffset = checkableOffset; + if (!m->icon.isNull() || !checkable) + textOffset += m->maxIconWidth; + } QRect textRect = subRule.contentsRect(opt->rect); - if (opt->direction == Qt::LeftToRight) - textRect.setLeft(textRect.left() + checkableOffset + iconOffset); - else - textRect.setRight(textRect.right() - checkableOffset - iconOffset); + textRect.setLeft(textRect.left() + textOffset); textRect.setWidth(textRect.width() - mi.tabWidth); + const QRect vTextRect = visualRect(opt->direction, m->rect, textRect); + QStringRef s(&mi.text); p->setPen(mi.palette.buttonText().color()); if (!s.isEmpty()) { @@ -3760,7 +3761,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q p->drawText(vShortcutRect, text_flags, s.mid(t + 1).toString()); s = s.left(t); } - p->drawText(textRect, text_flags, s.left(t).toString()); + p->drawText(vTextRect, text_flags, s.left(t).toString()); } if (mi.menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow @@ -5084,15 +5085,22 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op if (mi->text.contains(QLatin1Char('\t'))) width += 12; //as in QCommonStyle bool checkable = mi->checkType != QStyleOptionMenuItem::NotCheckable; + int checkableWidth = 0; if (checkable) { QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); QRect checkmarkRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); - width += checkmarkRect.width(); + checkableWidth = std::max(mi->maxIconWidth, checkmarkRect.width()); } if (!mi->icon.isNull()) { QPixmap pixmap = mi->icon.pixmap(pixelMetric(PM_SmallIconSize)); width += pixmap.width(); } + // padding overrules it all + if (!subRule.hasBox() || subRule.box()->paddings[LeftEdge] == 0) { + width += checkableWidth; + if (!mi->icon.isNull() || !checkable) + width += mi->maxIconWidth; + } return subRule.boxSize(subRule.adjustSize(QSize(width, csz.height()))); } } -- cgit v1.2.3 From eb60877fe96d82d9d6e1a834857744799e6de4db Mon Sep 17 00:00:00 2001 From: Kari Oikarinen Date: Wed, 30 Jan 2019 15:25:34 +0200 Subject: QWizard: Correctly calculate watermark size hint If we have have AA_EnableHighDpiScaling on and have loaded a @2x image, layout calculations can't use the real pixels of the QPixmap directly. Fixes: QTBUG-73401 Change-Id: I1891411a0e359e0148476f73b6cc3a128893a374 Reviewed-by: Friedemann Kleint --- src/widgets/dialogs/qwizard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 3876cf16c6..21e1ff2778 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -456,7 +456,7 @@ public: QSize minimumSizeHint() const override { if (pixmap() && !pixmap()->isNull()) - return pixmap()->size(); + return pixmap()->size() / pixmap()->devicePixelRatio(); return QFrame::minimumSizeHint(); } -- cgit v1.2.3 From f6edb0ef721c5c3734c2c05352febf0f9003ef6a Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Fri, 1 Feb 2019 15:34:49 +0300 Subject: Improve keyboard navigation in QListView when isWrapping is enabled Search the previous item or the next item in a model instead of searching them on visual layout. This way the cursor will not stop at the beginning or at the end of a row or a column. Fixes: QTBUG-14444 Change-Id: I0ef203a4dcd876e4c50559fb87e61585f07434d1 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qlistview.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 1248e91c8c..6b5857f1ca 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -1100,19 +1100,45 @@ QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie Q_D(QListView); Q_UNUSED(modifiers); - QModelIndex current = currentIndex(); - if (!current.isValid()) { + auto findAvailableRowBackward = [d](int row) { + while (row >= 0 && d->isHiddenOrDisabled(row)) + --row; + return row; + }; + + auto findAvailableRowForward = [d](int row) { int rowCount = d->model->rowCount(d->root); if (!rowCount) - return QModelIndex(); - int row = 0; + return -1; while (row < rowCount && d->isHiddenOrDisabled(row)) ++row; if (row >= rowCount) + return -1; + return row; + }; + + QModelIndex current = currentIndex(); + if (!current.isValid()) { + int row = findAvailableRowForward(0); + if (row == -1) return QModelIndex(); return d->model->index(row, d->column, d->root); } + if ((d->flow == LeftToRight && cursorAction == MoveLeft) || + (d->flow == TopToBottom && (cursorAction == MoveUp || cursorAction == MovePrevious))) { + const int row = findAvailableRowBackward(current.row() - 1); + if (row == -1) + return current; + return d->model->index(row, d->column, d->root); + } else if ((d->flow == LeftToRight && cursorAction == MoveRight) || + (d->flow == TopToBottom && (cursorAction == MoveDown || cursorAction == MoveNext))) { + const int row = findAvailableRowForward(current.row() + 1); + if (row == -1) + return current; + return d->model->index(row, d->column, d->root); + } + const QRect initialRect = rectForIndex(current); QRect rect = initialRect; if (rect.isEmpty()) { -- cgit v1.2.3 From a7ba79553c364df9ab55c5c177b15606191cd568 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 27 Jan 2019 21:04:25 +0100 Subject: QCommonStyle: factor out elided text calculation Factor out the calculation of the elided text from QCommonStylePrivate::viewItemDrawText() so it can be used by other painting functions. Change-Id: I28e6bfd2fe4d7c552848446fa9913df78589d15b Reviewed-by: Christian Andersen Reviewed-by: Richard Moe Gustavsen --- src/widgets/styles/qcommonstyle.cpp | 142 ++++++++++++++++++++---------------- src/widgets/styles/qcommonstyle_p.h | 5 ++ 2 files changed, 86 insertions(+), 61 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 3d626a57fa..867e91ab3e 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -843,8 +843,6 @@ static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbut } #endif // QT_CONFIG(toolbutton) -#if QT_CONFIG(itemviews) - static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth) { qreal height = 0; @@ -863,6 +861,80 @@ static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth) return QSizeF(widthUsed, height); } +QString QCommonStylePrivate::calculateElidedText(const QString &text, const QTextOption &textOption, + const QFont &font, const QRect &textRect, const Qt::Alignment valign, + Qt::TextElideMode textElideMode, int flags, + bool lastVisibleLineShouldBeElided, QPointF *paintStartPosition) const +{ + QTextLayout textLayout(text, font); + textLayout.setTextOption(textOption); + + viewItemTextLayout(textLayout, textRect.width()); + + const QRectF boundingRect = textLayout.boundingRect(); + // don't care about LTR/RTL here, only need the height + const QRect layoutRect = QStyle::alignedRect(Qt::LayoutDirectionAuto, valign, + boundingRect.size().toSize(), textRect); + + if (paintStartPosition) + *paintStartPosition = QPointF(textRect.x(), layoutRect.top()); + + QString ret; + qreal height = 0; + const int lineCount = textLayout.lineCount(); + for (int i = 0; i < lineCount; ++i) { + const QTextLine line = textLayout.lineAt(i); + height += line.height(); + + // above visible rect + if (height + layoutRect.top() <= textRect.top()) { + if (paintStartPosition) + paintStartPosition->ry() += line.height(); + continue; + } + + const int start = line.textStart(); + const int length = line.textLength(); + const bool drawElided = line.naturalTextWidth() > textRect.width(); + bool elideLastVisibleLine = false; + if (!drawElided && i + 1 < lineCount && lastVisibleLineShouldBeElided) { + const QTextLine nextLine = textLayout.lineAt(i + 1); + const int nextHeight = height + nextLine.height() / 2; + // elide when less than the next half line is visible + if (nextHeight + layoutRect.top() > textRect.height() + textRect.top()) + elideLastVisibleLine = true; + } + + QString text = textLayout.text().mid(start, length); + if (drawElided || elideLastVisibleLine) { + if (elideLastVisibleLine) { + if (text.endsWith(QChar::LineSeparator)) + text.chop(1); + text += QChar(0x2026); + } + const QStackTextEngine engine(text, font); + ret += engine.elidedText(textElideMode, textRect.width(), flags); + + // no newline for the last line (last visible or real) + // sometimes drawElided is true but no eliding is done so the text ends + // with QChar::LineSeparator - don't add another one. This happened with + // arabic text in the testcase for QTBUG-72805 + if (i < lineCount - 1 && + !ret.endsWith(QChar::LineSeparator)) + ret += QChar::LineSeparator; + } else { + ret += text; + } + + // below visible text, can stop + if (height + layoutRect.top() >= textRect.bottom()) + break; + } + return ret; +} + +#if QT_CONFIG(itemviews) + QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItem *option, int role) const { const QWidget *widget = option->widget; @@ -935,67 +1007,15 @@ void QCommonStylePrivate::viewItemDrawText(QPainter *p, const QStyleOptionViewIt textOption.setWrapMode(wrapText ? QTextOption::WordWrap : QTextOption::ManualWrap); textOption.setTextDirection(option->direction); textOption.setAlignment(QStyle::visualAlignment(option->direction, option->displayAlignment)); - QTextLayout textLayout(option->text, option->font); - textLayout.setTextOption(textOption); - - viewItemTextLayout(textLayout, textRect.width()); - - const QRectF boundingRect = textLayout.boundingRect(); - const QRect layoutRect = QStyle::alignedRect(option->direction, option->displayAlignment, - boundingRect.size().toSize(), textRect); - QPointF paintPosition = QPointF(textRect.x(), layoutRect.top()); - - QString newText; - qreal height = 0; - const int lineCount = textLayout.lineCount(); - for (int i = 0; i < lineCount; ++i) { - const QTextLine line = textLayout.lineAt(i); - height += line.height(); - - // above visible rect - if (height + layoutRect.top() <= textRect.top()) { - paintPosition.ry() += line.height(); - continue; - } - - const int start = line.textStart(); - const int length = line.textLength(); - - const bool drawElided = line.naturalTextWidth() > textRect.width(); - bool elideLastVisibleLine = false; - if (!drawElided && i + 1 < lineCount) { - const QTextLine nextLine = textLayout.lineAt(i + 1); - const int nextHeight = height + nextLine.height() / 2; - // elide when less than the next half line is visible - if (nextHeight + layoutRect.top() > textRect.height() + textRect.top()) - elideLastVisibleLine = true; - } - - QString text = textLayout.text().mid(start, length); - if (drawElided || elideLastVisibleLine) { - if (elideLastVisibleLine) { - if (text.endsWith(QChar::LineSeparator)) - text.chop(1); - text += QChar(0x2026); - } - const QStackTextEngine engine(text, option->font); - newText += engine.elidedText(option->textElideMode, textRect.width()); - // sometimes drawElided is true but no eliding is done so the text ends - // with QChar::LineSeparator - don't add another one. This happened with - // arabic text in the testcase for QTBUG-72805 - if (i < lineCount - 1 && - !newText.endsWith(QChar::LineSeparator)) - newText += QChar::LineSeparator; - } else { - newText += text; - } - // below visible text, can stop - if (height + layoutRect.top() >= textRect.bottom()) - break; - } + QPointF paintPosition; + const QString newText = calculateElidedText(option->text, textOption, + option->font, textRect, option->displayAlignment, + option->textElideMode, 0, + true, &paintPosition); - textLayout.setText(newText); + QTextLayout textLayout(newText, option->font); + textLayout.setTextOption(textOption); viewItemTextLayout(textLayout, textRect.width()); textLayout.draw(p, paintPosition); } diff --git a/src/widgets/styles/qcommonstyle_p.h b/src/widgets/styles/qcommonstyle_p.h index b347c8563a..f0131b7a58 100644 --- a/src/widgets/styles/qcommonstyle_p.h +++ b/src/widgets/styles/qcommonstyle_p.h @@ -62,6 +62,7 @@ QT_BEGIN_NAMESPACE // class QStringList; +class QTextOption; // Private class class Q_WIDGETS_EXPORT QCommonStylePrivate : public QStylePrivate @@ -85,6 +86,10 @@ public: #endif } + QString calculateElidedText(const QString &text, const QTextOption &textOption, + const QFont &font, const QRect &textRect, const Qt::Alignment valign, + Qt::TextElideMode textElideMode, int flags, + bool lastVisibleLineShouldBeElided, QPointF *paintStartPosition) const; #if QT_CONFIG(itemviews) void viewItemDrawText(QPainter *p, const QStyleOptionViewItem *option, const QRect &rect) const; void viewItemLayout(const QStyleOptionViewItem *opt, QRect *checkRect, -- cgit v1.2.3 From 7024090e1dc7043e7a2a692ede105bcb7952781d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 27 Jan 2019 21:15:52 +0100 Subject: QToolButton: fix handling multi-line texts The patch to elide the QToolButton text when there is not enough space introduced a regression with multi-line text. Fix it by using the newly introduced common function to elide multi-line text. Fixes: QTBUG-72226 Change-Id: I066ebbd2f360add93406cc29bb4bbbebf599ba42 Reviewed-by: Samuel Gaist Reviewed-by: Richard Moe Gustavsen --- src/widgets/styles/qcommonstyle.cpp | 22 ++++++++++++++++++++-- src/widgets/styles/qcommonstyle_p.h | 5 +++++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 867e91ab3e..79e338a6e7 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -1157,6 +1157,25 @@ void QCommonStylePrivate::viewItemLayout(const QStyleOptionViewItem *opt, QRect } #endif // QT_CONFIG(itemviews) +#if QT_CONFIG(toolbutton) +QString QCommonStylePrivate::toolButtonElideText(const QStyleOptionToolButton *option, + const QRect &textRect, int flags) const +{ + if (option->fontMetrics.horizontalAdvance(option->text) <= textRect.width()) + return option->text; + + QString text = option->text; + text.replace('\n', QChar::LineSeparator); + QTextOption textOption; + textOption.setWrapMode(QTextOption::ManualWrap); + textOption.setTextDirection(option->direction); + + return calculateElidedText(text, textOption, + option->font, textRect, Qt::AlignTop, + Qt::ElideMiddle, flags, + false, nullptr); +} +#endif // QT_CONFIG(toolbutton) #if QT_CONFIG(tabbar) /*! \internal @@ -1705,8 +1724,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, alignment |= Qt::AlignLeft | Qt::AlignVCenter; } tr.translate(shiftX, shiftY); - const QString text = toolbutton->fontMetrics.elidedText(toolbutton->text, Qt::ElideMiddle, - tr.width(), alignment); + const QString text = d->toolButtonElideText(toolbutton, tr, alignment); proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette, toolbutton->state & State_Enabled, text, QPalette::ButtonText); diff --git a/src/widgets/styles/qcommonstyle_p.h b/src/widgets/styles/qcommonstyle_p.h index f0131b7a58..296f89ce5f 100644 --- a/src/widgets/styles/qcommonstyle_p.h +++ b/src/widgets/styles/qcommonstyle_p.h @@ -115,6 +115,11 @@ public: && option.viewItemPosition == cachedOption->viewItemPosition); } #endif +#if QT_CONFIG(toolbutton) + QString toolButtonElideText(const QStyleOptionToolButton *toolbutton, + const QRect &textRect, int flags) const; +#endif + mutable QIcon tabBarcloseButtonIcon; #if QT_CONFIG(tabbar) void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const; -- cgit v1.2.3