Does PyQt5 have QMap?
Solved
Qt for Python
-
Qt has QMap, I wonder does PyQt5 have QMap also, I can't find out.
-
@darrenleeleelee1 Python already has a map data structure
-
@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.
-
@jsulm Sorry, I got stuck.
Can you give me a hint?
I want to translate this from c++ to pythonQMap<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>()); } }
-
Hi,
What issue do you have ?
What do you expect ?
What do you get ?