Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListWidget: DragDrop event Signal
Forum Updated to NodeBB v4.3 + New Features

QListWidget: DragDrop event Signal

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.5k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fem_dev
    wrote on 28 Aug 2019, 20:16 last edited by
    #1

    I setted a QListWidget property as:

    ui->mylist->setDragDropMode(QAbstractItemView::InternalMove);
    

    Now I can drag and drop the internal list items. Ok!

    I would like to know how to get a Qt signal when this internal dragdrop event occurs.
    I look in the official documentation but I'm not founding this signal event:
    https://doc.qt.io/qt-5/qlistwidget.html

    Is this possible?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Aug 2019, 20:42 last edited by
      #2

      Hi,

      Because it doesn't exist.

      What would you like to do on drop ?

      By the way, did you already read the drag and drop chapter for item views in Qt's documentation ?

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

      F 1 Reply Last reply 29 Aug 2019, 14:05
      1
      • S SGaist
        28 Aug 2019, 20:42

        Hi,

        Because it doesn't exist.

        What would you like to do on drop ?

        By the way, did you already read the drag and drop chapter for item views in Qt's documentation ?

        F Offline
        F Offline
        fem_dev
        wrote on 29 Aug 2019, 14:05 last edited by fem_dev
        #3

        @sgaist thanks for the information, but now I don't know how to implement my idea:

        I have a main application called "Job Manager" and it loads my custom developed plugins.
        For now, I called these plugins: "Analysis X", "Analysis Y" and "Analysis Z".

        The input data for each plugin is a custom QJsonObject with diferent fields and values.

        I would like that the user choose your plugin sequence and write your input data for each plugin in independent way.

        So, here is a exemple:
        0_1567086202472_job_manager_1.jpg

        The user can select a "Avaliable plugin" and add it to the "Added Analysis" QListWidget.

        My problem is related with how can I store/manage the individual QJsonObjects to send the correct input data for each "added" plugin in the list.

        Below, I did a exemple that the user adds 5 times the same plugin "Analysis X", but he wants to set a diferent QJsonObject for each "Analysis X" instance.
        After this add process, the user will get something like this:
        0_1567086308237_job_manager_2.jpg

        You can see in the Qt Creator IDE console that the QJsonObject is the same for each instance.

        I store these configurations in a QMap<int, QJsonObject>, where the key is the QListWidgetItem index and the QJsonObject is the custom configuration (GUI input) for each plugin instance.

        My problem is:
        If I modify the values of each plugin instance (set different values for the "name" field) AND dragdrop (reordering using dradropMode = InternalMove) the QListWidgetItems I loose the relationship between the Item index and the QJsonObject input data.

        Look this image:
        0_1567087016912_job_manager_3.jpg

        In this case, I will run the "Analysis X" plugin 5 times sequentially, but the QJsonObject input data for each instance is wrong now!

        So I would like to get something like a "Qt Signal" when the users drapdrop items (reordering using dradropMode = InternalMove) the QListWidget to match the Item index and the QJsonObejct stored in the QMap<int, QJsonObejct.

        Just the QMap store section of my C++ code:

        void job_manager::add_item()
        {
            // ===== JSON SECTION =====
            // Get it on QMap:
            auto plugin = _plugin_map[selected_item];
            // Get plugin input variables:
            QJsonObject input = plugin->get_input_variables();
            // Insert the index (int) and input data (QJsonObject) in a QMap
            _properties->insert(id, input);
        }
        

        Coul you help me?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fem_dev
          wrote on 29 Aug 2019, 17:17 last edited by
          #4

          Well, I solved this missing Qt signal replacing the drapdrop mouse operation by 2 buttons: "move item to up" and "move item to down".

          Here is a example of "move item to up" implementation:

          void MainWindow::on_up_btn_clicked()
          {
              int current_id = ui->add_list->currentRow();
              int target_id = current_id - 1;
          
              // Error checking: first element
              if (current_id > 0)
              {
                  // Get the current item text:
                  QString current_item = ui->add_list->item(current_id)->text();
                  // Get the current QJsonObject:
                  QJsonObject current_json = my_array->at(current_id).toObject();
          
                  // Get the target item text:
                  QString target_item = ui->add_list->item(target_id)->text();
                  // Get the target QJsonObject:
                  QJsonObject target_json = my_array->at(target_id).toObject();
          
                  // Store a temp QJsonObject to swap:
                  QJsonObject temp = target_json;
          
                  // Replace items text:
                  ui->add_list->item(target_id)->setText(current_item);
                  ui->add_list->item(current_id)->setText(target_item);
          
                  // Replace QJsonObjects:
                  my_array->replace(current_id, temp);
                  my_array->replace(target_id, current_json);
          
                  // Set current row:
                  ui->add_list->setCurrentRow(target_id);
              }
          }
          
          1 Reply Last reply
          0
          • F Offline
            F Offline
            fem_dev
            wrote on 29 Aug 2019, 17:44 last edited by
            #5

            A more generic solution could be:

            void swap_items(QListWidget* list, QJsonArray* array, int current_id, int target_id)
            {
                // Get the current item text:
                QString current_item = list->item(current_id)->text();
                // Get the current QJsonObject:
                QJsonObject current_json = array->at(current_id).toObject();
            
                // Get the target item text:
                QString target_item = list->item(target_id)->text();
                // Get the target QJsonObject:
                QJsonObject target_json = array->at(target_id).toObject();
            
                // Store a temp QJsonObject to swap:
                QJsonObject temp = target_json;
            
                // Replace items text:
                list->item(target_id)->setText(current_item);
                list->item(current_id)->setText(target_item);
            
                // Replace QJsonObjects:
                array->replace(current_id, temp);
                array->replace(target_id, current_json);
            
                // Set current row:
                list->setCurrentRow(target_id);
            }
            
            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 29 Aug 2019, 17:50 last edited by SGaist
              #6

              One other possibility would be to implement your own QAbstractListModel on top of your object list. That way you would directly manipulate the structure without additional back and forth of your data.

              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
              0

              1/6

              28 Aug 2019, 20:16

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved