On QTreeView, I set the context menu. The menu itself is generated upon request from the server, depending on which item of the tree is selected (for the folder, one thing, for the final item, another). I got the menu. I hooked the triggered () signal to my slot. And already in the slot I sent my signal with the data I needed. The problem is that the data I need come in a request from the server. How to add them to QMenu, so that later when you click on a menu item to get this data. For example, in a certain Tag or, as in the case of QTreeView, I add the data for different roles to its model, and then I can get this data by index. How to be?
1 answer
Found a solution to your question. Thanks to the all-knowing internet. When forming the menu, I used the QAction setter to add the data I needed. Connect the triggered signal with its slot
QAction *act = new QAction(QIcon(":/ico/"+valueIcon+".ico"),valueText); act->setData(value); connect(act, SIGNAL(triggered()),SLOT(menuClicked())); menu->addAction(act);
Well, in the slot I got the data as follows:
QAction *action = qobject_cast<QAction*>(sender()); QString datamenu = action->data().toString();
I do not know how beautiful it is, but it works as I need.
|