Results 1 to 5 of 5

Thread: QtreeWidgetItem: setFlags emits QTreeWidget::itemChanged

  1. #1
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QtreeWidgetItem: setFlags emits QTreeWidget::itemChanged

    From the doc http://doc.qt.nokia.com/stable/qtree...html#setFlags:

    void QTreeWidgetItem::setFlags ( Qt::ItemFlags flags )

    Sets the flags for the item to the given flags. These determine whether the item can be selected or modified. This is often used to disable an item.
    and from http://doc.qt.nokia.com/stable/qtree...l#itemChanged:

    void QTreeWidget::itemChanged ( QTreeWidgetItem * item, int column ) [signal]

    This signal is emitted when the contents of the column in the specified item changes.
    But when I call item->setFlags(...) with which I don't change the contents of the column, a itemChanged signal is thrown.
    My problem is that I have a plugin connected to that signal and it should react only when the content has been changed, not the flags.

    Is there an elegant way to solve this problem ? (I have a solution but it looks more like a hack).

    thanks

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QtreeWidgetItem: setFlags emits QTreeWidget::itemChanged

    This depend on interpretation of contents of item.
    IMO flags are part of item contents, since it has impact on how item can be visualized (as you quote documentation: "This is often used to disable an item.")
    Check the flag values: http://doc.trolltech.com/latest/qt.html#ItemFlag-enum
    Qt::ItemIsEnabled, Qt::ItemIsTristate, Qt::ItemIsUserCheckable - those flags are definitely have impact on how item is drawn (content).

    Maybe you should try to connect to different signal, for example QAbstractItemModel::dataChanged .

  3. #3
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtreeWidgetItem: setFlags emits QTreeWidget::itemChanged

    Yes, probably it's right, itemChanged is thrown because the flags of the item are changed.
    But the docs specifies "the content of the item", this is why I was a bit surprised when I've seen that the signal is thrown also when I change the flags.
    Thanks for the suggestion but how should I use that signal ? I've never used models, that's my problem.
    I guess I have to connect to the model of the QTableWidget...


    Added after 5 minutes:


    I've tried now in this way:
    Qt Code:
    1. connect (m_TreeWidget->model(), SIGNAL(dataChanged (const QModelIndex&, const QModelIndex&)),
    2. this , SLOT (ItemDataChanged(const QModelIndex&, const QModelIndex&)) );
    To copy to clipboard, switch view to plain text mode 
    but the signal is emitted also when the flags are set.
    Thanks anyway.
    Last edited by trallallero; 16th November 2011 at 08:03.

  4. #4
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtreeWidgetItem: setFlags emits QTreeWidget::itemChanged

    Did you ever find a solution? I have a similar problem. My slot that I connected to the itemChanged signal is being called way too often. I want to only know when the checkstate is changed, is that possible? Any suggestions?

  5. #5
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtreeWidgetItem: setFlags emits QTreeWidget::itemChanged

    I've solved in this (hacky) way:

    Qt Code:
    1. void PluginOptions::On_itemDoubleClicked(QTreeWidgetItem *item, int column)
    2. {
    3. m_SessionActive = true;
    4.  
    5. <set the flags>
    6.  
    7. m_SessionActive = false;
    8. }
    9.  
    10. void PluginOptions::On_itemChanged(QTreeWidgetItem* item, int column)
    11. {
    12. if (m_SessionActive)
    13. return;
    14. <...>
    15. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 4
    Last Post: 22nd September 2011, 20:37
  2. QTreeWidget::setCurrentItem ( QTreeWidgetItem * item )
    By gboelter in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2011, 23:21
  3. Unable to remove QTreeWidgetItem row from Qtreewidget
    By moh.gup@gmail.com in forum Qt Programming
    Replies: 2
    Last Post: 1st December 2010, 06:40
  4. Customizing QTreeWidget and QTreeWidgetItem
    By mots_g in forum Qt Programming
    Replies: 0
    Last Post: 18th August 2010, 07:53
  5. Replies: 2
    Last Post: 24th May 2009, 11:27

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.