summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2024-05-04 16:11:01 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2024-05-08 19:58:17 +0200
commit5ea248155654b58fcb52ef326dc4d94de83d0409 (patch)
tree5c79dd8133bc675ead077235fc660d9690ab328b /tests/auto/widgets/kernel
parentc587eeef11a00866347e44ec4e701c7775558a07 (diff)
QWidget: fix render() in RTL mode
Rendering a widget to a paintdevice via QWidget::render() did not pass the LayoutDirection mode of the widget to the paintdevice which lead to wrong rendering of text. This is especially visible with the windows 11 style which does not draw some widgets directly on the screen but through a QGraphicsEffect on a QImage. Pick-to: 6.7 6.5 6.2 Fixes: QTBUG-124931 Change-Id: If2cfa326d2ca45c42e203a4ae91fd857afa5c69c Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
Diffstat (limited to 'tests/auto/widgets/kernel')
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 94bf9fff5c..3447c9af28 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -319,6 +319,7 @@ private slots:
void renderTargetOffset();
void renderInvisible();
void renderWithPainter();
+ void renderRTL();
void render_task188133();
void render_task211796();
void render_task217815();
@@ -8474,6 +8475,47 @@ void tst_QWidget::renderWithPainter()
QCOMPARE(painter.renderHints(), oldRenderHints);
}
+void tst_QWidget::renderRTL()
+{
+ QFont f;
+ f.setStyleStrategy(QFont::NoAntialias);
+ const QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("Windows")));
+
+ QMenu menu;
+ menu.setMinimumWidth(200);
+ menu.setFont(f);
+ menu.setStyle(style.data());
+ menu.addAction("I");
+ menu.show();
+ menu.setLayoutDirection(Qt::LeftToRight);
+ QVERIFY(QTest::qWaitForWindowExposed(&menu));
+
+ QImage imageLTR(menu.size(), QImage::Format_ARGB32);
+ menu.render(&imageLTR);
+ //imageLTR.save("/tmp/rendered_1.png");
+
+ menu.setLayoutDirection(Qt::RightToLeft);
+ QImage imageRTL(menu.size(), QImage::Format_ARGB32);
+ menu.render(&imageRTL);
+ imageRTL = imageRTL.mirrored(true, false);
+ //imageRTL.save("/tmp/rendered_2.png");
+
+ QCOMPARE(imageLTR.height(), imageRTL.height());
+ QCOMPARE(imageLTR.width(), imageRTL.width());
+ static constexpr auto border = 4;
+ for (int h = border; h < imageRTL.height() - border; ++h) {
+ // there should be no difference on the right (aka no text)
+ for (int w = imageRTL.width() / 2; w < imageRTL.width() - border; ++w) {
+ auto pixLTR = imageLTR.pixel(w, h);
+ auto pixRTL = imageRTL.pixel(w, h);
+ if (pixLTR != pixRTL)
+ qDebug() << "Pixel do not match at" << w << h << ":"
+ << Qt::hex << pixLTR << "<->" << pixRTL;
+ QCOMPARE(pixLTR, pixRTL);
+ }
+ }
+}
+
void tst_QWidget::render_task188133()
{
QMainWindow mainWindow;