0

So I have 2 QGraphicsScenes with QGraphicsViews in my ui. In those QGraphicScenes are QGraphicsItems, now I want to make my program wait to let the user select one QGraphicsItem om each Scene, but how do I do this?

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

Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
Cédric Vandelaer
  • 153
  • 1
  • 5
  • 13

1 Answers1

2

you can make a slot and connect the selectionChanged signals of both GraphicsScenes to it. 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.

WoJo
  • 360
  • 2
  • 10
  • but then i still cant force the user to make a selection :S I just want nothing to happen untill the user has made a selection :S the slot will only be triggered when he selects something :S – Cédric Vandelaer Jun 10 '13 at 15:49
  • I don't know your program and so I don't know what else could happen. But there are ways to "force" the user. for example, you can show the selection views in a modal dialog. – WoJo Jun 10 '13 at 16:11
  • 1
    @Cédric Vandelaer Define 'nothing happens'. If you keep the main loop busy with `while`, nothing really happens, and user can not select an element. It's obviously not what you want. It's your program, you should decide when particular GUI elements should be enabled/disabled, shown/hidden, etc. – Pavel Strakhov Jun 10 '13 at 16:11
  • ehm i want to pause the main loop of the program and let the user still be able to select a qgraphicsitem from the views. So the main loop should be paused untill something is selected – Cédric Vandelaer Jun 10 '13 at 19:04
  • this is possible. start your widget with the graphic views inside a own QEventLoop and call exec from the main loop. the new loop runs until you call exit from your widget. the main loop remains at the exec call until it returns. – WoJo Jun 10 '13 at 19:11
  • This is bad practice. You should never make the main loop busy for a long time. If you really need to do this, still don't do this. Fix the architecture of your app instead. – Pavel Strakhov Jun 10 '13 at 19:26