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

HiDPI: Bottom/right lines visible when fill rectangles on QWidget

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.15.1
    • 5.9.3
    • GUI: Painting
    • None
    • Linux/X11
    • b4aee30692c166025b4e2283c19dbc1247bcce54 (qt/qtbase/dev) 5de4b9b1e5eb1ae8d922ee96d88eb6bba05b2b45 (qt/qtbase/5.15)

    Description

      when two consective update request are issued (assume first one with QRect(158,87 300x150), the second with
      QRect(158,87 301x149)), qt may combine two as one with a single QRegion(size=2, bounds=(158,87 301x150) - [(158,87 301x149), (158,236 300x1)]). now given QT_SCALE_FACTOR equals 1.25, the scaled region would be QRegion(size=2, bounds=(198,109 376x187) - [(198,109 376x186), (198,295 375x1)]). this makes a problem where Qt combines the two QRect as a QRegion and then scales it.
      what if we reverse the process, the result will be slightly different (i.e. scale two QRects seperately and then combine into one QRegion). the resulting QRegion would be QRegion(size=2, bounds=(198,109 376x187) - [(198,109 376x186), (198,295 375x2)]).
      the height should have been 2px smaller, but due to the calculation error (150 * 1.25 = 187.5(188) 149 * 1.25 = 186.25(186)), the result is 1px smaller, which cause an artifact on the screen (1px high).

      Example:

      class TestWindow : public QWidget
      {
      public:
          explicit TestWindow(QWidget *parent = 0)
              : QWidget(parent) {}
      
          void mousePressEvent(QMouseEvent *e)
          {
              if (e->button() == Qt::LeftButton) {
                  press_pos = e->pos();
              } else {
                  color = Qt::transparent;
                  update(rect);
                  rect = rect.marginsRemoved(QMargins(0, 0, -1, 1));
                  color = Qt::red;
                  update(rect);
              }
          }
      
          void mouseMoveEvent(QMouseEvent *e)
          {
              color = Qt::transparent;
              update(rect);
              rect.setLeft(qMin(press_pos.x(), e->pos().x()));
              rect.setTop(qMin(press_pos.y(), e->pos().y()));
              rect.setRight(qMax(press_pos.x(), e->pos().x()));
              rect.setBottom(qMax(press_pos.y(), e->pos().y()));
              color = Qt::red;
              update(rect);
          }
      
          void paintEvent(QPaintEvent *e)
          {
              QPainter pa(this);
      
      //        pa.setCompositionMode(QPainter::CompositionMode_Source);
              qDebug() << e->region() << rect;
              pa.fillRect(rect, color);
          }
      
          QPoint press_pos;
          QRect rect;
          QColor color;
      };
      
      int main(int argc, char *argv[])
      {
          qputenv("QT_SCALE_FACTOR", "1.25");
          QApplication a(argc, argv);
      
          TestWindow testWidnow;
      
          testWidnow.setWindowFlags(testWidnow.windowFlags() | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus);
          testWidnow.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
            zccrs JiDe Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes