Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Does PyQt5 have QMap?
Forum Updated to NodeBB v4.3 + New Features

Does PyQt5 have QMap?

Scheduled Pinned Locked Moved Solved Qt for Python
7 Posts 3 Posters 1.2k Views 2 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.
  • D Offline
    D Offline
    darrenleeleelee1
    wrote on last edited by
    #1

    Qt has QMap, I wonder does PyQt5 have QMap also, I can't find out.

    jsulmJ 1 Reply Last reply
    0
    • D darrenleeleelee1

      Qt has QMap, I wonder does PyQt5 have QMap also, I can't find out.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @darrenleeleelee1 Python already has a map data structure

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      2
      • jsulmJ jsulm

        @darrenleeleelee1 Python already has a map data structure

        D Offline
        D Offline
        darrenleeleelee1
        wrote on last edited by
        #3

        @jsulm You mean dictionay right?
        Can I QMap<int,QVariant> implement this in PyQt to get the int and item mapping?

        jsulmJ 1 Reply Last reply
        0
        • D darrenleeleelee1

          @jsulm You mean dictionay right?
          Can I QMap<int,QVariant> implement this in PyQt to get the int and item mapping?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @darrenleeleelee1 said in Does PyQt5 have QMap?:

          Can I QMap<int,QVariant> implement this in PyQt to get the int and item mapping?

          Yes, why not? Just try.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 2 Replies Last reply
          1
          • jsulmJ jsulm

            @darrenleeleelee1 said in Does PyQt5 have QMap?:

            Can I QMap<int,QVariant> implement this in PyQt to get the int and item mapping?

            Yes, why not? Just try.

            D Offline
            D Offline
            darrenleeleelee1
            wrote on last edited by darrenleeleelee1
            #5

            @jsulm Ok, I try it now.Thanks.

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @darrenleeleelee1 said in Does PyQt5 have QMap?:

              Can I QMap<int,QVariant> implement this in PyQt to get the int and item mapping?

              Yes, why not? Just try.

              D Offline
              D Offline
              darrenleeleelee1
              wrote on last edited by darrenleeleelee1
              #6

              @jsulm Sorry, I got stuck.
              Can you give me a hint?
              I want to translate this from c++ to python

              QMap<int,QVariant> modelData;
              for(;;){
                  mimeReader.startTransaction();
                  mimeReader >> row >> col >> modelData;
                  if(!mimeReader.commitTransaction())
                      break;
                  const auto userRoleIter = modelData.constFind(Qt::UserRole);
                  if(userRoleIter!=modelData.cend())
                      doSomethingWithModule(userRoleIter->value<Module>());
              }
              

              I translate like this, but I not sure how to fix.

              def dragEnterEvent(self, event: QtGui.QDragEnterEvent) -> None:
                      super().dragEnterEvent(event)
                      print(type(event.mimeData().data('application/x-qabstractitemmodeldatalist')))
                      mimeReader = QDataStream(event.mimeData().data('application/x-qabstractitemmodeldatalist'))
                      row = 0
                      col = QtCore.QVariant
                      while(True):
                          mimeReader.startTransaction()
                          mimeReader >> row >> col
                          print(row, col)
                          if(not mimeReader.commitTransaction()):
                              break
              

              full c++ code is here

              void dropEvent(QGraphicsSceneDragDropEvent *event){
              	const QByteArray mimeData = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
              	QDataStream mimeReader(mimeData);
              	int row,col;
              	QMap<int,QVariant> modelData;
              	for(;;){
              		mimeReader.startTransaction();
              		mimeReader >> row >> col >> modelData;
              		if(!mimeReader.commitTransaction())
              			break;
              		const auto userRoleIter = modelData.constFind(Qt::UserRole);
              		if(userRoleIter!=modelData.cend())
              			doSomethingWithModule(userRoleIter->value<Module>());
              	}
              }
              
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                What issue do you have ?
                What do you expect ?
                What do you get ?

                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