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

Item data not copied on drag-n-drop if column is hidden

    XMLWordPrintable

    Details

    • Platform/s:
      Windows

      Description

      Steps to reproduce:
      1) Create QTreeView with these properties: dragDropMode:DragDrop, defaultDropAction:MoveAction, selecetionBehavior:SelectRows
      2) Populate it with QStandardItemModel composed of 2 rows and 2 columns (Enter simple text for item's DisplayRole)
      3) Hide 2nd column
      4) DragMove one row to another position
      5) Unhide 2nd column

      #include <QtWidgets>
      
      class Test : public QMainWindow
      {
          Q_OBJECT
      public:
          Test() {
              QWidget *central = new QWidget();
      
              mTreeView = new QTreeView();
              mTreeView->setDragDropMode(QTreeView::DragDrop);
              mTreeView->setDefaultDropAction(Qt::MoveAction);
              mTreeView->setSelectionBehavior(QTreeView::SelectRows);
      
              QGridLayout *gridLayout = new QGridLayout(central);
      
              QStandardItemModel *model = new QStandardItemModel(2, 2);
              for (int row = 0; row < 2; ++row) {
                  for (int column = 0; column < 2; ++column) {
                      QStandardItem *item = new QStandardItem(QString("r %0, c %1").arg(row).arg(column));
                      model->setItem(row, column, item);
                  }
              }
              mTreeView->setModel(model);
      
              mHideColumn = new QPushButton("Hide");
              mShowColumn = new QPushButton("Show");
      
              connect(mHideColumn, SIGNAL(clicked()),
                      this, SLOT(hideColumn()));
              connect(mShowColumn, SIGNAL(clicked()),
                      this, SLOT(showColumn()));
      
              gridLayout->addWidget(mTreeView);
              gridLayout->addWidget(mHideColumn);
              gridLayout->addWidget(mShowColumn);
      
              setCentralWidget(central);
          }
      
          ~Test() {
              delete mTreeView->model();
          }
      
      public slots:
          void hideColumn() {
              mTreeView->hideColumn(1);
          }
      
          void showColumn() {
              mTreeView->showColumn(1);
              mTreeView->resizeColumnToContents(0);
              mTreeView->resizeColumnToContents(1);
          }
      private:
          QTreeView *mTreeView;
          QPushButton *mHideColumn;
          QPushButton *mShowColumn;
      };
      
      int main (int argc, char *argv[])
      {
          QApplication a(argc, argv);
          Test test;
          test.resize(400, 400);
          test.show();
          return a.exec();
      }
      
      #include "main.moc"
      

      Result: The DisplayRole value of the moved item (2nd column) is completely lost. Not only for the DisplayRole but any other role. If the 2nd column is not hidden it works fine.

        Attachments

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

          Activity

            People

            Assignee:
            richard Richard Moe Gustavsen
            Reporter:
            marcus.fr Marcus Frenkel
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes