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. Getting information about dragged item - QTreeWidgetItem
Forum Updated to NodeBB v4.3 + New Features

Getting information about dragged item - QTreeWidgetItem

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.6k 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.
  • O Offline
    O Offline
    Ouims
    wrote on last edited by
    #1

    Hello,

    I have a QTreeWidget with only one column.
    This column has one top item with some subitem, and some of these subitem have some subsubitem:

    main
      subitem
          subsubitem1
          subsubitem2
          subsubitem3
      subitem1
          subsubitem11
          subsubitem12
          subsubitem13
    

    Only subsubitem are draggable.

    QByteArray e = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
    		QDataStream stream(&e, QIODevice::ReadOnly);
    		QString dropped;
    
    		while (!stream.atEnd()) {
    			int row, col;
    			QMap<int, QVariant> roleDataMap;
    
    			stream >> row >> col >> roleDataMap;
    
    			dropped = roleDataMap[0].toString();
    		}
    

    This get the text of the item, col is always 0 but row isn't enough to tell which item is parent.
    If i drag subsubitem3, row = 2, being an index only tied to the parent item, how to get the parent, or how to solve this?
    Note that I'm dropping into a QTextEdit of another class, I can't access my QTreeWidget from there

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi and welcome to devnet,

      What exactly do you want to get in your QTextEdit ?

      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
      • O Offline
        O Offline
        Ouims
        wrote on last edited by
        #3

        The handling of the drag and drop is done already, but depending on the parent item, i need to use a different member
        The QTextEdit doesn't matter, that part is working, i just need to get the parent of the item

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          In that case, shouldn't you rather provide everything in the dragged data ? Otherwise, you'll be starting a tight coupling between widgets who shouldn't need to know anything from each other.

          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
          • O Offline
            O Offline
            Ouims
            wrote on last edited by
            #5

            Well, I wouldn't be asking here if I knew what I should do.
            Let's breakdown this more, the app is an editor, the QTreeWidget item which are draggable are filename (not complete, only filename) but i do have a vector of complete filename to be used when we need to open that file, I do not want to display the complete filename in the tree.
            While working on the drag and drop into the Qtextedit, i only used the filename i had in the tree as testing purpose (dropping on a tabbar of a QTabWidget which contains the QTextedit creates a new tab, but if you drop on the qtextedit at some specific part, it splits the view, and create a new qtabwidget with a tab where the text of that tab is 'dropped' from the code in my first post.
            But to access the corresponding complete filename in my vector to open the file, i need to use the index of item in the tree.
            However I do have a problem of 'communication' between my class. At first i was just playing around so i made a main class inheriting qmainwindow which has my tree and the different vectors, but I made a second class inheriting QTabwidget and all the drag and drop event of the QTextedit are then handled from that class. Are you suggesting that I get rid of that second class and that i put everything in my main class? I admit that when i started I was unsure about signals and i thought i had to create another class to access the event such as drag&drop here, but i could use signals from my main class, correct?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              In that case, it looks like a QTreeView with a custom model would be better.

              From that model, you can then provide all the data that your various widgets need through QMimeData and thus make them independent of the source.

              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

              • Login

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