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

QTableView draws grid outside of header

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.9.4
    • 5.6.0, 5.6.1, 5.6.2, 5.7.0, 5.7.1, 5.8.0, 5.9.0 Beta 1, 5.9.0, 5.9.1
    • Widgets: Itemviews
    • None
    • 5c0a9fc532d70ae784cca3e16b5fe59862902815

    Description

      (See attachment)

      Minimal example:

      #include <QMdiArea>
      #include <QMdiSubWindow>
      #include <QStringListModel>
      #include <QTableView>
      #include <QLabel>
      #include <QApplication>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QMdiArea mdiArea;
          mdiArea.show();
      
          QStringList stringList;
          for (int i = 1; i <= 10; i++)
              stringList << QString("bla").repeated(i);
      
          QTableView *tableView = new QTableView(&mdiArea);
          QStringListModel *model = new QStringListModel(stringList, tableView);
          tableView->setMinimumSize(800, 600);
          tableView->setModel(model);
      
          QMdiSubWindow *tableWindow = mdiArea.addSubWindow(tableView, Qt::Window);
          tableWindow->show();
      
          QMdiSubWindow *labelWindow = mdiArea.addSubWindow(new QLabel("<h1>oh my grid!<br>for what?</h1>"), Qt::Window);
          labelWindow->move(300, 100);
          labelWindow->show();
      
          return a.exec();
      }
      

      Possible reason:

      void QTableView::paintEvent(QPaintEvent *event)
      {
          uint x = horizontalHeader->length() - horizontalHeader->offset() - (rightToLeft ? 0 : 1);
          uint y = verticalHeader->length() - verticalHeader->offset() - 1;
          ...
          for (QRect dirtyArea : region) {
              dirtyArea.setBottom(qMin(dirtyArea.bottom(), int(y)));
              if (rightToLeft) {
                  dirtyArea.setLeft(qMax(dirtyArea.left(), d->viewport->width() - int(x)));
              } else {
                  dirtyArea.setRight(qMin(dirtyArea.right(), int(x)));
              }
             // and dirtyArea may be invalid: 
             // dirtyArea.right() == x && x < dirtyArea.left()
             // dirtyArea.bottom() == y && y < dirtyArea.top()
              ...
              if (showGrid) {
                  ...
                  // even if dirtyArea.right() < dirtyArea.left()
                  painter.drawLine(dirtyArea.left(), rowY + rowh, dirtyArea.right(), rowY + rowh);
                  ...
                  // even if dirtyArea.bottom() < dirtyArea.top()
                  painter.drawLine(colp, dirtyArea.top(), colp, dirtyArea.bottom());
              }
          }
      }
      

      Attachments

        1. example.png
          example.png
          41 kB
        2. grid.png
          grid.png
          8 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
              octobergun Evgeny Soglaev
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes