Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-129914

QPainter drawText(int x, int y, int width, int height, ...) doesn't work if width or height is zero

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.8.1, 6.9.0 FF
    • 6.8.0
    • GUI: Painting
    • None
    • CPU: AMD Ryzen 7 5700G
      GPU: CPU inbuild
      Graphic resolution: 4K
      Graphic scaling: 200%
      OS: Windows 11 23H2 Build 22631.4317
    • Windows
    • b587e7143 (dev), a012e558d (6.8)

    Description

      In Qt 6.7.2 and below QPainter:drawText(x, y, w, h, ...) in combination with Qt::TextDontClip flag zero values for width and height parameters work:

      #include <QApplication>
      #include <QWidget>
      #include <QPainter>
      
      class Widget : public QWidget
      {
      protected:
          void paintEvent(QPaintEvent *)
          {
              QPainter painter(this);
              painter.setRenderHints(QPainter::Antialiasing, true);
              auto Width = width();
              auto Height = height();
              auto Side = qMin(Width, Height);
              painter.scale(Side / 600.0, Side / 600.0);
      
              QFont font("arial",20);
              painter.setFont(font);
      
              // works in Qt 6.7.2 and below, but doesn't work since Qt 6.8.0
              painter.drawText(50, 50, 0, 0, Qt::TextDontClip | Qt::TextSingleLine,  QString("Hallo"));
      
              // works in Qt 6.8.0 if values for width and height are at least 1
              painter.drawText(50, 50, 1, 1, Qt::TextDontClip | Qt::TextSingleLine, QString("Hallo"));     }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          Widget w;
          w.show();
          return a.exec();
      }
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vgt Eirik Aavitsland
            mireiner Chris
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes