Results 1 to 4 of 4

Thread: py qt newbie itemDoubleClicked?

  1. #1
    Join Date
    Jan 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default py qt newbie itemDoubleClicked?

    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.

    Qt Code:
    1. class StartQT4(QtGui.QMainWindow):
    2. def __init__(self, parent=None):
    3. QtGui.QWidget.__init__(self, parent)
    4. self.ui = Ui_notepad()
    5. self.ui.setupUi(self)
    6. # here we connect signals with our slots
    7. QtCore.QObject.connect(self.ui.editor_window,QtCore.SIGNAL("itemDoubleClicked()"), self.open_preview)
    8. QtCore.QObject.connect(self.ui.button_open,QtCore.SIGNAL("clicked()"), self.file_dialog)
    9. def file_dialog(self):
    10. self.ui.editor_window.addItems(list)
    11. def open_preview(self):
    12. self.ui.bottom_window.addItems('adsfakdsfadfadsfasdf')
    13.  
    14. if __name__ == "__main__":
    15. app = QtGui.QApplication(sys.argv)
    16. myapp = StartQT4()
    17. myapp.show()
    18. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

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

    any thoughts?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: py qt newbie itemDoubleClicked?

    You can override the function QWidget::mouseDoubleClickEvent to catch the double click.
    You could do something like..
    Qt Code:
    1. YourWindow::mouseDoubleClickEvent( QMouseEvent * event )
    2. {
    3. statusBar()->showMessage("Mouse double clicked");
    4. }
    To copy to clipboard, switch view to plain text mode 
    Hope thiss helps....

  3. #3
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    1
    Platforms
    Windows

    Default Re: py qt newbie itemDoubleClicked?

    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.

    Qt Code:
    1. def mouseDoubleClickEvent(self, event):
    2. statusBar().showMessage("Mouse double clicked")
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    1
    Platforms
    Windows

    Default Re: py qt newbie itemDoubleClicked?

    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.

Similar Threads

  1. Replies: 3
    Last Post: 17th June 2007, 20:23
  2. Replies: 1
    Last Post: 15th March 2007, 20:45
  3. Newbie - experiences with Qt
    By masoroso in forum General Discussion
    Replies: 1
    Last Post: 3rd May 2006, 14:44
  4. QT/Win 4.1.1 with VisualStudio2005 Newbie
    By skaiser in forum Installation and Deployment
    Replies: 9
    Last Post: 24th March 2006, 02:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.