Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Drag & Drop event end

    General and Desktop
    2
    3
    1070
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      moravas last edited by

      Hi Folks,

      I have a small application, where I'm using QTableView with QStandardItemModel. I enabled the drag & drop whithin the table.
      My problem is, that I couldn't find an lightweight, stange-forward way to detect the exact finish of drag & drop, when the model is in the final state, which is visible for the user.

      Can anybody tell me, how should I catch this?

      Regards,
      Nobert

      1 Reply Last reply Reply Quote 0
      • M
        moravas last edited by

        Hi,

        I checked your suggestion, and I tried out with the following code:
        @
        view->horizontalHeader()->setSectionsMovable(true);
        view->verticalHeader()->setSectionsMovable(true);

        connect(view->horizontalHeader(),   &QHeaderView::sectionMoved, [this](int, int, int) {qDebug() << "horizontal";});
        connect(view->verticalHeader(),     &QHeaderView::sectionMoved, [this](int, int, int) {qDebug() << "vertical";});
        

        @

        but nothing was happening.
        could you provide me some code example, how should I use the headerView?

        Regards,
        Nobert

        can Anybody help me?

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          @
          QTableView *tableWidget = new QTableView;
          QStandardItemModel *itemModel = new QStandardItemModel;
          tableWidget->setModel(itemModel);

          itemModel->setColumnCount(4);
          itemModel->setRowCount(5);
          
          for (int col = 0 ; col < itemModel->columnCount() ; ++col) {
              for (int row = 0 ; row < itemModel->rowCount() ; ++row) {
                  QStandardItem *item = new QStandardItem(tr("Test %1 %2").arg(col).arg(row));
                  itemModel->setItem(row, col, item);
              }
          }
          
          tableWidget->horizontalHeader()->setSectionsMovable(true);
          tableWidget->verticalHeader()->setSectionsMovable(true);
          

          @

          With that you can move rows up and down and columns left to right

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 0
          • First post
            Last post