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

QTreeWidget::visualItemRect() only returns rect for first column

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.6.1
    • 4.4.2
    • Widgets: Itemviews
    • None
    • e6558e8b25897ba9ac0a553509a0056915b0eb5c

    Description

      The documentation for QTreeWidget::visualItemRect() states: "Returns the rectangle on the viewport occupied by the item at item."
      So it should return the area occupied by all columns. The code below shows that only the rect of the first column is returned instead. This is because in the function implementation, it reads:

      return visualRect(d->index(item));

      The default value for the second parameter is 0, meaning first column.

      // -------------------------------------------------
      #include <QtGui>

      class TreeWidget : public QTreeWidget
      {
      public:
      TreeWidget( QWidget * parent = 0 ) : QTreeWidget( parent )

      { setColumnCount( 2 ); QStringList list; list << "*" << "*"; item = new QTreeWidgetItem( list ); addTopLevelItem( item ); }

      protected:
      virtual void paintEvent( QPaintEvent * e )

      { QTreeWidget::paintEvent( e ); QPainter painter( viewport() ); painter.setPen( Qt::red ); painter.drawRect( visualItemRect( item ) ); }

      private:
      QTreeWidgetItem * item;
      };

      class MainWindow : public QMainWindow
      {
      public:
      MainWindow() : QMainWindow()

      { QWidget * centralWidget = new QWidget; setCentralWidget( centralWidget ); QVBoxLayout * layout = new QVBoxLayout; centralWidget->setLayout( layout ); TreeWidget * tree = new TreeWidget( this ); layout->addWidget( tree ); }

      };

      int main( int argc, char * argv[] )
      {
      QApplication app( argc, argv );
      MainWindow mainWindow;
      mainWindow.show();
      return app.exec();
      }
      // -------------------------------------------------

      Attachments

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

        Activity

          People

            vfm Thierry Bastian (closed Nokia identity) (Inactive)
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes