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

Square drawn at the end of a dashed line.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.6.3, 5.9.2
    • 5.7.1, 5.10.0 Alpha
    • GUI: Painting
    • None
    • I'm using Qt 5.7.1 on windows 10 with MinGW 5.3.0.

    Description

      Hello,

      I think I have the same problem.

      I am drawing dashed QGraphicsLineItems, and in some rare [line position, zoom factor] configurations, I get a square at the end of the dashed line (see attachment).

      Here is a minimal example:

       

      #include <QApplication>
      #include <QMainWindow>
      #include <QGraphicsScene>
      #include <QGraphicsView>
      #include <QGraphicsLineItem>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QMainWindow w;
      
          QGraphicsScene* scene = new QGraphicsScene(&w);
          QGraphicsView* view = new QGraphicsView(scene);
      
          w.setCentralWidget(view);
      
          QGraphicsLineItem* line = new QGraphicsLineItem(0, 0, 120, 90);
          QPen pen;
          pen.setStyle(Qt::DashLine);
          line->setPen(pen);
          scene->addItem(line);
      
          // The problem occurs only with some scaling factors
          // 3.160913184460621305760241739335469901561737060546875 is one of them
          // Many others can be found, for example by successively
          // calling view->scale(1.01, 1.01)
          qreal f = 3.160913184460621305760241739335469901561737060546875;
          view->scale(f, f);
      
          w.setMinimumSize(700, 700);
          w.show();
          return a.exec();
      }
      

      Here are some miscellaneous observations that may - or not - be useful:

      • the bug seems to occur preferentially for some line angles. dx / dy = 4/3 (or 3/4) seems to be especially bug-prone
      • changing the widget size affects the size of the square artifact
      • for some custom dash patterns, the bug seems to disappear completely (at least I can't reproduce it), but for others, it seems to be more frequent. For example pen.setDashPattern({8, 3}) seems fine, but pen.setDashPattern({8, 2}) seems bug-prone

       

      Attachments

        1. dashline.png
          dashline.png
          8 kB
        2. qtbug56969.zip
          2 kB
        3. shot012.png
          shot012.png
          1.46 MB
        For Gerrit Dashboard: QTBUG-56969
        # Subject Branch Project Status CR V

        Activity

          People

            vgt Eirik Aavitsland
            alexadams Alex Adams
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes