Results 1 to 6 of 6

Thread: Custom context menu in QTreeView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom context menu in QTreeView

    I added

    Qt Code:
    1. connect(model, SIGNAL(itemChanged(QStandardItem * item)), SLOT(myItemChanged(QStandardItem *item)));
    2.  
    3. // where QStandardItemModel *model = new QStandardItemModel();
    To copy to clipboard, switch view to plain text mode 

    from my MainWindow (inherits from QMainWindow) and
    Qt Code:
    1. void MainWindow::myItemChanged(QStandardItem *item)
    2. {
    3. changeItemState(item);
    4. }
    5.  
    6. void MainWindow::changeItemState(QStandardItem *item)
    7. {
    8. if (!item)
    9. return;
    10. for (int i=0; i<item->rowCount(); ++i) {
    11. QStandardItem *child = item->child(i);
    12. child->setCheckable(item->checkState());
    13. changeItemState(child);
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    similar to your example but the two methods weren't invoked at all when I toggle the checkbox.
    TNG

  2. #2
    Join Date
    Jan 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default (Fixed) Custom context menu in QTreeView

    Quote Originally Posted by ttvo View Post
    I added

    Qt Code:
    1. connect(model, SIGNAL(itemChanged(QStandardItem * item)), SLOT(myItemChanged(QStandardItem *item)));
    2.  
    3. // where QStandardItemModel *model = new QStandardItemModel();
    To copy to clipboard, switch view to plain text mode 
    The correct code is:
    Qt Code:
    1. connect(model, SIGNAL(itemChanged(QStandardItem * )), SLOT(myItemChanged(QStandardItem *)));
    To copy to clipboard, switch view to plain text mode 
    TNG

Similar Threads

  1. Custom QTreeWidgetItem context menu?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 1st February 2010, 04:42
  2. Replies: 7
    Last Post: 23rd March 2009, 21:01
  3. Shortcut key for context menu
    By darshan.hardas in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:32
  4. Replies: 4
    Last Post: 25th June 2007, 20:40
  5. Q3TextEdit custom context menu
    By bcteh_98 in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 21:00

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.