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

QDrawUtil: qDrawPlainRoundedRect does not work well for high-dpi screens

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.9.1, 6.10.0 FF
    • 6.8
    • Widgets: Styles
    • None
    • All
    • 1fb86f1f8 (dev), f349040b3 (6.9), 45f39ab5b (6.8), 611031e4f (dev), d6802feee (6.9)

    Description

      qDrawPlainRoundedRect was derived from qDrawPlainRect but due to the rounded borders it does not work well with high-dpi screens:

      Code to reproduce the issue:

      QPixmap drawPlainRoundedRect(qreal dpr, int lw) {
      	QPixmap pm(100, 100);
      	pm.setDevicePixelRatio(dpr);
      	QColor col(Qt::green);
      	col.setAlpha(128);
      	QBrush brush(col);
      	QRect rect = QRect(20 / dpr, 20 / dpr, 60 / dpr, 60 / dpr);
      	pm.fill(Qt::black);
      	QPainter p(&pm);
      	//qDrawPlainRect(&p, rect, Qt::red, lw, &brush);
      	qDrawPlainRoundedRect(&p, rect, 4, 4, Qt::red, lw, &brush);
      	p.end();
      	return pm;
      }
      
      int main(int argc, char* argv[]) {
      	QApplication app(argc, argv);
      	QList<qreal> ratios = { 1.0, 1.11, 1.83, 2.75 };
      	QList<int> lineWidths = { 1, 2, 3, 4 };
      	QPixmap pixmap(400, 400);
      	QPainter p(&pixmap);
      	for (int i = 0; i < ratios.size(); ++i) {
      		for (int j = 0; j < lineWidths.size(); ++j) {
      			auto pm = drawPlainRoundedRect(ratios.at(i), lineWidths.at(j));
      			pm.setDevicePixelRatio(1);
      			p.drawPixmap(i * 100, j * 100, pm);
      		}
      	}
      	p.end();
      	pixmap.save("out.png");
      	return 0;
      }
      

      qDrawPlainRect() also does some useless double-work so it should be cleaned up too.

      Attachments

        1. out_r_new.png
          out_r_new.png
          0.7 kB
        2. out_r_old.png
          out_r_old.png
          0.7 kB
        3. out_rr_new.png
          out_rr_new.png
          1 kB
        4. out_rr_old.png
          out_rr_old.png
          1 kB
        5. out_r_new-1.png
          out_r_new-1.png
          1 kB
        6. out_r_old-1.png
          out_r_old-1.png
          1 kB
        7. out_rr_new-1.png
          out_rr_new-1.png
          3 kB
        8. out_rr_old-1.png
          out_rr_old-1.png
          3 kB
        9. out_bevel_plainrect.png
          out_bevel_plainrect.png
          2 kB
        10. out_miter_plainrect.png
          out_miter_plainrect.png
          1 kB

        Issue Links

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

          Activity

            People

              chehrlic Christian Ehrlicher
              chehrlic Christian Ehrlicher
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: