PDA

View Full Version : py qt newbie itemDoubleClicked?



gateway
10th January 2008, 22:33
I create a small designer gui with a button that loads in some files from a db, and displays them in a window, my next step is I want to double click on the output and launch or do something.. for example double click on an item in the list and pop up a window saying ok, just as a start.

here is some of the code but so far I cant get double click to work for some reason.


class StartQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_notepad()
self.ui.setupUi(self)
# here we connect signals with our slots
QtCore.QObject.connect(self.ui.editor_window,QtCor e.SIGNAL("itemDoubleClicked()"), self.open_preview)
QtCore.QObject.connect(self.ui.button_open,QtCore. SIGNAL("clicked()"), self.file_dialog)
def file_dialog(self):
self.ui.editor_window.addItems(list)
def open_preview(self):
self.ui.bottom_window.addItems('adsfakdsfadfadsfas df')

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = StartQT4()
myapp.show()
sys.exit(app.exec_())

right now if i double click on something it should print adsfakdsfadfadsfasdf in bottom_window

any thoughts?

aamer4yu
11th January 2008, 14:21
You can override the function QWidget::mouseDoubleClickEvent to catch the double click.
You could do something like..

YourWindow::mouseDoubleClickEvent( QMouseEvent * event )
{
statusBar()->showMessage("Mouse double clicked");
}Hope thiss helps....

giverson
11th January 2008, 15:19
translated to Python...place this in the QMainWindow class

You can use the passed in event to get x, y coords for the click, as well.



def mouseDoubleClickEvent(self, event):
statusBar().showMessage("Mouse double clicked")

giverson
12th January 2008, 02:04
think we misread what you were trying to do earlier...I do see where you pulled the example for that.

For that, I would suggest going with QListWidget instead. It has built in support for item selection and stuff like that and is built especially for that. Overload the QListWidget to create a custom widget and overwrite those member classes in your custom QListWidget.

I don't know if that ui_widget has that slot or not because I've never messed with the edytor library.

http://docs.huihoo.com/pyqt/pyqt4/html/qlistwidget.html

Also, I would use addItem instead of addItems for adding 1 item. Probably incurs less overhead.

And if you go to that link and go up 1 folder, it has all the Qt classes that Trolltech provides documentation before except the documentation is for Python and PyQt. Enjoy. :)