Results 1 to 19 of 19

Thread: Checked item in QTreeWidget?

  1. #1
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Checked item in QTreeWidget?

    Hi All,

    I am working on qt 4.2.2 on my MAC Tiger.
    I have a project in which I am change the state of a QTreeWidgetItem when an item is checked or unchecked.

    This is working fine in qt 4.2.2 but when i tried this code on qt 4.3.2 then more often the item is not get checked or unchecked when i click on the item.

    I want to ask whether it is due to Qt 4.3.2 or i have to do something different to do it.

    Thanks.

  2. #2
    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: Checked item in QTreeWidget?

    Can we see the code?

  3. #3
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Checked item in QTreeWidget?

    Hi,

    I m having a QTreeWidget and inserting item in the treeWidget as follows.
    Qt Code:
    1. QTreeWidgetItem *item = new QTreeWidgetItem(MyTreeWidget);
    2. item->setText(0,"My Text");
    3. item->setIcon(0,icon);
    4. item->setText(1,"--");
    5. item->setCheckState(0,Qt::Unchecked);
    To copy to clipboard, switch view to plain text mode 

    and when I click on the item in the treeWidget on Qt 4.2.2 it is checked immediately but when i am using this code in Qt 4.3.2 then the item is not checked immediately (often) and sometime it is not even checked and also giving the look of disable treeWidget.

  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: Checked item in QTreeWidget?

    Try adding:
    Qt Code:
    1. item->setFlags(item->flags()|Qt::ItemIsUserCheckable);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Checked item in QTreeWidget?

    Thanks for reply.

    but it doesnot making any difference.
    I donot know why the item is getting disable sometimes when click on item.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Checked item in QTreeWidget?

    How do you react to check state changes? Show the slot, please.
    J-P Nurmi

  7. #7
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Re: Checked item in QTreeWidget?

    Actually I m updating the state of the current item parent in the treeWidget and link list.

    It has 4 function which i m using and its not possible to post them.
    But I can assure that they all are running well in Qt 4.2.2 but donot know why there is a problem in the Qt 4.3.2.

    Even if I donot use them then still the item is not checked.

  8. #8
    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: Checked item in QTreeWidget?

    Can you provide a minimal compilable example reproducing the problem?

  9. #9
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Checked item in QTreeWidget?

    Hi,

    I m attaching a code.In it i have a treeWidget on which when i clicked sometimes item is not checked or unchecked.
    Attached Files Attached Files

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Checked item in QTreeWidget?

    Does it work properly with another style, for example with plastique?
    ./app -style plastique
    J-P Nurmi

  11. #11
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Checked item in QTreeWidget?

    Yes the problem remains even after changing the Style.

  12. #12
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Checked item in QTreeWidget?

    Hi,

    No Answer????.
    So Am I right it a problem of qt 4.3.2

  13. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Checked item in QTreeWidget?

    The only problem I'm experiencing with 4.3.2 is that the area that responds to check state changes is a bit too far left. With 4.3.3 it works perfectly.
    J-P Nurmi

  14. #14
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Checked item in QTreeWidget?

    Hi jpn,

    So you are saying that if I use qt 4.3.3 then this problem should not arise.

  15. #15
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Checked item in QTreeWidget?

    I can't say for sure. Your description "sometimes item is not checked or unchecked" is vague.

    As I said, for me with Qt 4.3.2 check states change but I can notice that the area that reacts to checking is a bit too left, not exactly over the drawn check box (see the attached explanatory screenshot). With Qt 4.3.3 it reacts exactly over the drawn check box.
    Attached Images Attached Images
    J-P Nurmi

  16. #16
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Checked item in QTreeWidget?

    By saying "Sometimes item is not checked or unchecked" I mean that sometimes item check state change on the signle click and sometimes I click several times on item and its check state does not changed.

  17. #17
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Checked item in QTreeWidget?

    Quote Originally Posted by vishal.chauhan View Post
    sometimes item check state change on the signle click and sometimes I click several times on item and its check state does not changed.
    Even if you keep mouse at exactly the same position? I don't have such problem with Qt 4.3.2.
    J-P Nurmi

  18. #18
    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: Checked item in QTreeWidget?

    Maybe this is OS specific? I don't have 4.3.2 installed anywhere so I can't verify it here, but if J-P tested it and it worked fine, then I don't see why it should fail elsewhere. Could you check if the same thing happens when using examples bundled with Qt?

  19. #19
    Join Date
    Dec 2007
    Location
    Austin, TX
    Posts
    43
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Checked item in QTreeWidget?

    It appears that the check box in a tree (or list) view doesn't change when checked (4.3.2) -- which if fixed in 4.3.3 means I can remove some code I added to "fix" it.

    I added a:

    Qt Code:
    1. connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(clickCheck(QListWidgetItem*)));
    To copy to clipboard, switch view to plain text mode 

    and for the slot:

    Qt Code:
    1. void clickCheck(QListWidgetItem* item)
    2. {
    3. if (item->checkState() == Qt::Unchecked)
    4. item->setCheckState(Qt::Checked);
    5. else
    6. item->setCheckState(Qt::Unchecked);
    7. }
    To copy to clipboard, switch view to plain text mode 

    This allows the user to click on the label for the check box & get the box toggled. (Boy, I hope 4.3.3 allows me to remove this code... although it makes it nicer for users, maybe I'll keep it either way)

    Vycke

Similar Threads

  1. How to know wich item is clicked QTreeWidget
    By ^NyAw^ in forum Qt Programming
    Replies: 13
    Last Post: 6th November 2007, 23:47
  2. QTreeWidget select item
    By ^NyAw^ in forum Qt Programming
    Replies: 7
    Last Post: 26th October 2007, 14:26
  3. Inserting Item to a QTreeWidget from Thread?
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2007, 11:23
  4. QTreeWidget item editing: want column specificity
    By McKee in forum Qt Programming
    Replies: 12
    Last Post: 10th December 2006, 22:12
  5. Removing items properly from qtreewidget item
    By Djony in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2006, 12:20

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.