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

QTreeWidget::visualrect return wrong values after moving columns

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.11.0 Alpha
    • 4.8.2, 4.8.4, 5.1.0 Beta 1
    • Widgets: Itemviews
    • None
    • Linux

    Description

      There are some problems getting items visualRect from a QTreeWidget.

      There is QTreeWidget with 2 columns and a QTreeWidgetItem item inside. At this time, item visualRect is the expected one (something like 20, 0, 200, 18).

      Now column is moved from visual index 1 to visual index 0 (header()->moveSection(1, 0)). If you try to get item visualRect you will see it is not the expected one. You will get an invalid QRect (0,0,0,0), despite the fact that an item cell is visible.

      There is an example attached.
      Run the example and you will see a TreeWidget with an item inside.
      Click the button 'Print item visualRect", you will get something like (20, 0, 200, 18) which is ok.
      Now click button "Move and hide column with index 1" (does exactly what is says).
      Now click the button 'Print item visualRect" again. You get an invalid item visualRect (should not be invalid since item can be seen in the view)

      If hiding of the column is removed the problem is still valid.
      However the rect of the cells are correct.

      void MyWidget::onPrintButtonClicked() 
      { 
          QRect r = tree->visualItemRect(item); 
          qDebug("Item visual rect (%d %d %d %d)", r.x(), r.y(), r.width(), r.height()); 
          for(int i=0; i<tree->model()->columnCount();i++) { 
              r = tree->visualRect(tree->model()->index(0,i)); 
              qDebug("Item visual rect (%d %d %d %d)", r.x(), r.y(), r.width(), r.height()); 
          } 
      } 
      

      Attachments

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

        Activity

          People

            stephen.kelly Stephen Kelly (Unused account) (Inactive)
            qtcomsupport Qt Support
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes