Results 1 to 2 of 2

Thread: How to check/interpret itemChanged signal for QTreeWidget?

  1. #1
    Join Date
    Oct 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default How to check/interpret itemChanged signal for QTreeWidget?

    Hi, I'm trying to make a checkable QTreeWidget, however I don't know how or if I can use the ItemChanged signal to know exactly which box's have been checked or unchecked? Is there a way to tell what specific box has changed? This is what I have so far:
    Qt Code:
    1. QMainWindow(parent),
    2. ui(new Ui::MainWindow)
    3. {
    4. QTreeWidgetItem *itm = new QTreeWidgetItem(ui->treeWidget);
    5. itm->setText(0,"1");
    6. itm->setFlags(itm->flags() | Qt::ItemIsUserCheckable);
    7. itm->setCheckState(0,Qt::Checked);
    8.  
    9. AddChild(itm,"2");
    10. AddChild(itm,"3");
    11. AddChild(itm,"4");
    12. }
    13.  
    14. void MainWindow::AddChild(QTreeWidgetItem *parent,QString title)
    15. {
    16. itm->setText(0,title);
    17. itm->setFlags(itm->flags() | Qt::ItemIsUserCheckable);
    18. itm->setCheckState(0,Qt::Checked);
    19. parent->addChild(itm);
    20. }
    21.  
    22. void MainWindow::on_treeWidget_itemChanged(QTreeWidgetItem *item, int column)
    23. {
    24. //What do I put here?
    25. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to check/interpret itemChanged signal for QTreeWidget?

    Quote Originally Posted by Jaz View Post
    void MainWindow:n_treeWidget_itemChanged(QTreeWidgetItem *item, int column)
    {
    //What do I put here?
    }
    [/code]
    Qt Code:
    1. const bool checked = item->checkState(0) == Qt::Checked;
    To copy to clipboard, switch view to plain text mode 
    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 22nd August 2013, 11:50
  2. QtreeWidgetItem: setFlags emits QTreeWidget::itemChanged
    By trallallero in forum Qt Programming
    Replies: 4
    Last Post: 30th January 2012, 08:58
  3. QTreeWidget - extending check-box capabilities
    By mcherkas in forum Qt Programming
    Replies: 2
    Last Post: 1st November 2011, 12:51
  4. Replies: 5
    Last Post: 7th July 2010, 05:58
  5. QTreeWidget (Row Check, Custom Sort)
    By AaronMK in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2008, 16:55

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.