简体   繁体   English

Qt等待用户在QGraphicsScene中选择项目

[英]Qt wait for user to select items in QGraphicsScene

So I have 2 QGraphicsScene s with QGraphicsView s in my ui . 所以我在我的ui中有2个QGraphicsSceneQGraphicsView In those QGraphicScene s are QGraphicsItem s, now I want to make my program wait to let the user select one QGraphicsItem om each Scene, but how do I do this? 在那些QGraphicSceneQGraphicsItem ,现在我想让我的程序等待让用户在每个场景中选择一个QGraphicsItem ,但是我该怎么做呢?

I've tried things like: 我尝试过这样的事情:

while(scene->selectedItems().length()<1 || bordScene->selectedItems().length()<1)
    ;

But this will just cause the program to go in an infinite loop and the user still won't be able to select items. 但这只会导致程序进入无限循环,用户仍然无法选择项目。

This is probably a pretty simple question but I can't seem to find a simple solution 这可能是一个非常简单的问题,但我似乎无法找到一个简单的解决方案

you can make a slot and connect the selectionChanged signals of both GraphicsScenes to it. 你可以创建一个插槽并将两个GraphicsScenes的selectionChanged信号连接到它。 in the slot, you can check the selected items. 在插槽中,您可以检查所选项目。 since the slot is only triggered when the selection of one of the connected GraphicsScenes has changed, you have no infinite loop and your programm will not be blocked. 由于仅在选择其中一个连接的GraphicsScenes时触发了插槽,因此您没有无限循环,并且您的程序不会被阻止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM