[PyQt] QGraphicsView item select

Alfredo Junior junixrj at yahoo.com
Wed Apr 11 14:02:09 BST 2012


OK.

This is a functional example:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

def itemSelected(self):
    print "Selection changed"
    
app = QApplication(sys.argv)
grview = QGraphicsView()
scene = QGraphicsScene()
scene.addPixmap(QPixmap('on.png'))
grview.setScene(scene)
scene.selectionChanged.connect(itemSelected)
grview.show()
sys.exit(app.exec_())

It should run the function itemSelected and print "Selection changed" when I click on the picture (little green square).

My first post:

> I am writing a PyQt application.
> There is a sqlite database where I store data collected from the mame games(mamedev.org).
> I created a QGraphicsView with the screens of the games.
> Also created a QTableWidget with information about the games.
> Now, I need these items to be selectable (simultaneously).
> The moment I select a game in QTableWidget, it must be selected in QGraphicsView (if it exists) and vice versa.
> I have no idea how can I do this.

> Bellow the image of my application:
> http://img7.imagebanana.com/img/zt5ok20w/LorenaMameFrontend_006.png

Thanks.



----- Original Message -----
From: Andreas Pakulat <apaku at gmx.de>
To: "pyqt at riverbankcomputing.com" <pyqt at riverbankcomputing.com>
Cc: 
Sent: Wednesday, April 11, 2012 3:50 AM
Subject: Re: [PyQt] QGraphicsView item select

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

_______________________________________________
PyQt mailing list    PyQt at riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: on.png
Type: image/png
Size: 384 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120411/9d410a0a/attachment.png>


More information about the PyQt mailing list