Results 1 to 3 of 3

Thread: TreeView click item not connecting

  1. #1
    Join Date
    May 2006
    Posts
    28
    Thanks
    8
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default TreeView click item not connecting

    Hi,

    I have a treeview connected to a standardItemModel
    I want to connect a click on an item do do something with current index.
    Qt Code:
    1. treeView = new MyTreeView;
    2. model = new QStandardItemModel(0,12);
    3.  
    4. treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
    5. treeView->setSelectionMode(QAbstractItemView::SingleSelection);
    6. treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    7. treeView->setModel(model);
    8. treeView->header()->setClickable(true);
    9. connect(treeView, SIGNAL(clicked()), this, SLOT(doGameInfo()));
    To copy to clipboard, switch view to plain text mode 

    Ive got some rows in the model and I click on a row, nothing happens.
    My connect should work should'nt it ?

    I dont see why the index could be invalid so thats not the problem ?

    Qt Code:
    1. public:
    2. QTreeView *treeView;
    3. private slots:
    4. void doGameInfo();
    To copy to clipboard, switch view to plain text mode 

    I even tried sub classing QTreeView to re-code :
    void clicked ( const QModelIndex & index );

    but no luck, any pointers anyone ?
    Thanks, Neil

  2. #2
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: TreeView click item not connecting

    You might want to change the signature of the signal coming from the QTreeView. It should be:
    Qt Code:
    1. connect(treeView, SIGNAL(clicked( QModelIndex )), this, SLOT(doGameInfo()));
    To copy to clipboard, switch view to plain text mode 

    If you don't include the data types of the parameters passed by the signal, Qt won't recognize it.

  3. The following user says thank you to Jimmy2775 for this useful post:

    Big Duck (9th June 2006)

  4. #3
    Join Date
    May 2006
    Posts
    28
    Thanks
    8
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: TreeView click item not connecting

    Thanks, I new it had to be something so simple as that!

    i had tried - obviously needed more sleep , less programming
    Qt Code:
    1. connect(treeView, SIGNAL(clicked( const QModelIndex & index ), this, SLOT(doGameInfo()));
    To copy to clipboard, switch view to plain text mode 

    many thanks.

Similar Threads

  1. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 01:34
  2. Replies: 5
    Last Post: 12th January 2006, 15:40

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.