Results 1 to 4 of 4

Thread: Need help getting QAbstractItemView syntax correct

  1. #1
    Join Date
    Dec 2008
    Posts
    13

    Default Need help getting QAbstractItemView syntax correct

    Hi,

    I can't figure out how to properly connect an instance of a QAbstractItemView to a signal. I've tried all kinds of different things based on bits that I've read but have yet to stumble on the magic formula.

    What I'm trying to do is connect the arrow keys to a QTreeView so that when the user scrolls up and down the tree then another function is called. Based on what I've read the proper way to do this is through using the QAbstractItemView and connect to selectionModel().

    Here's my latest version:

    treeModel = self.ui.areaTree.selectionModel()
    QtCore.QObject.connect(treeModel, QtCore.SIGNAL(QtGui.QAbstractItemView.CursorAction ), self.keyPress)

    I'm using Python and PyQt4. I've broken out the treeModel just to make sure I had accessed it properly. Can someone please point out the proper code.

    Thanks

  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: Need help getting QAbstractItemView syntax correct

    QAbstractItemView is a abstract class.. you will need to inherit that class or use some other classes such as QlistView, QTreeView or QTableview in order to use it properly.

  3. #3
    Join Date
    Dec 2008
    Posts
    13

    Default Re: Need help getting QAbstractItemView syntax correct

    I thought I had inherited it with treeModel when I grabbed selectionModel() from the Tree Widget. I thought that QAbstractItemView <- QTreeView <- QTreeWidget, so selectionModel gives you an extenstion of the view. Is that not correct?

    If not could you point me to an example where it is used correctly.

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need help getting QAbstractItemView syntax correct

    The model doesn't have the view's signals. You are trying to connect a signal defined in the view class using a model object. You have to at least change treeModel = self.ui.areaTree.selectionModel() to treeModel = self.ui.areaTree.

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.