[PyQt] QGraphicsView item select

Andreas Pakulat apaku at gmx.de
Wed Apr 11 07:50:55 BST 2012


On 10.04.12 20:05:19, Alfredo Junior wrote:
> Thank you for your help.
> 
> But I can't make something like that.
> 
> In my example only tableWidget works:
> 
> class Init(QtGui.QMainWindow):
>     def __init__(self):
>         super(Init, self).__init__()
>         self.initUI()
>     def initUI(self):
>         uic.loadUi(os.path.join(os.getcwd(), "ui/window.ui"), self)
>         self.scene = QtGui.QGraphicsScene()
>         pixItem = QtGui.QPixmap("picture.png")
>         self.scene.addItem(pixItem)
> 
>         self.graphicsView.setScene(self.scene)
>         # my problem [begin]
> self.scene.selectionChanged.connect(self.gameSelected)
>         # my problem [end]
>         self.tableWidget.selectionModel().selectionChanged.connect(self.gameSelected)
>     def gameSelected(self):
>         print "Selection changed"
> 
> The scene.selectionChanged doesn't work.
> 
> Some tip?

No, since you didn't provide a minimal example that I could try out or
provide more information on what exactly "doesn't work" means (is the
slot called at all for example). Its also not advisable to use the same
slot-function for both selection-changed signals since they have
different parameters and you'll need to write different code in each to
get the selected elements.

Andreas



More information about the PyQt mailing list