Results 1 to 14 of 14

Thread: QTreeWidget question

  1. #1
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question QTreeWidget question

    Hi,

    I want to do like this (see the attached image). In qt3 it was solved simple use a QCheckViewItem class, but I can't find a similar solution in qt4 . Can anyone help me with this issue?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget question

    im not remember QCheckViewItem in qt 3
    It was QCheckListItem imho In qt4 it must be QTreeWidgetItem.

  3. #3
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget question

    Quote Originally Posted by zlatko
    im not remember QCheckViewItem in qt 3
    It was QCheckListItem imho In qt4 it must be QTreeWidgetItem.
    Sorry, I made a mistake . I know about QTreeWidgetItem, but its behaviour does not allow me to design TreeView as illustrated in the attached image or probably, I have not found a correct way for it .

  4. #4
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeWidget question

    Hello Man,

    Since Qt 4.1, you have a new method in QTreeWidget to do this !

    Qt Code:
    1. void QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget )
    To copy to clipboard, switch view to plain text mode 

    With this, you can set your checkboxes !

    Guilugi.

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget question

    item delegates may work as well.
    Reading the doc about Model/View architecture should help you a lot !
    Current Qt projects : QCodeEdit, RotiDeCode

  6. #6
    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: QTreeWidget question

    Use QTreeWidgetItem::setFlags() and add Qt::ItemIsUserCheckable flag to the flags for that item. You can then use QTreeWidgetItem::setCheckState() and QTreeWidgetItem::checkState() to manipulate the checkbox.

  7. #7
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget question

    Quote Originally Posted by wysota
    Use QTreeWidgetItem::setFlags() and add Qt::ItemIsUserCheckable flag to the flags for that item. You can then use QTreeWidgetItem::setCheckState() and QTreeWidgetItem::checkState() to manipulate the checkbox.
    Thanks all for your help in search of the solution of my problem, but all suggested solutions do not allow to make as I want. It allow to create checkboxes AFTER display of tree only, but I need to have checkboxes which is leveled to a left border, BEFORE tree (such as in an attached image) .
    Attached Images Attached Images

  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: QTreeWidget question

    It's a wild guess, but try setting those checkboxes for the last column for example and then move the last column before the first one. I doubt it'll work, but you might try it anyway.

    You may have to subclass QTreeWidget to achieve the thing you want by reimplementing drawRow from the tree and drawing that checkbox yourself for every item, just be carefull not to break branching and indenting of items.

    A simple solution would be to disable indentation completely, this way all checkboxes would form a vertical line like you want them to.

    Reimplementing the delegate won't help, as it is only responsible for drawing the item itself and the item in a tree starts after the branching lines.

  9. #9
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget question

    Quote Originally Posted by wysota
    It's a wild guess, but try setting those checkboxes for the last column for example and then move the last column before the first one. I doubt it'll work, but you might try it anyway.
    Probably... but in my case the row should present an united unit of information and I need to manipulate every row as a single whole. Unfortunately I can't to use this solution because theoretically I don't know number of columns.

    Quote Originally Posted by wysota
    You may have to subclass QTreeWidget to achieve the thing you want by reimplementing drawRow from the tree and drawing that checkbox yourself for every item, just be carefull not to break branching and indenting of items.
    I tried this solution. Sure, I can draw a some region (similar to QCheckBox), I can catch a mouse button press on this region through mousePressEvent method, but this region will not be QCheckBox in point of fact. I cannot know a condition of this control. It would be desirable to find more comfortable solution for me and for users of course...
    Quote Originally Posted by wysota
    A simple solution would be to disable indentation completely, this way all checkboxes would form a vertical line like you want them to.
    In this case I can't have a show of tree hierarchy

    The some ambush around...

  10. #10
    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: QTreeWidget question

    Quote Originally Posted by Mad Max
    Probably... but in my case the row should present an united unit of information and I need to manipulate every row as a single whole. Unfortunately I can't to use this solution because theoretically I don't know number of columns.
    So try that with a second column. I really doubt it works, but.... I just don't have better ideas You can always ask the Trolls if there is a solution for this.

  11. #11
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget question

    Quote Originally Posted by wysota
    It's a wild guess, but try setting those checkboxes for the last column for example and then move the last column before the first one. I doubt it'll work, but you might try it anyway.
    I solved it thus. Slightly awry, but it work ok. Thanks all and special thanks to wysota for the active participation.

  12. #12
    Join Date
    Feb 2006
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget question

    Hi,

    Just to add to that question,

    If I want to have functionality as such,
    1. Upon checking/unchecking the parent QtreeWidgetItem checkbox,
    ->the children are corresponding changed to the parent item's checkbox state.

    I've tried connecting the signal in the following way to address this, but it doesn't seem to work

    QTreeWidgetItem *poRecord = new QTreeWidgetItem(ThisTreeWidget);
    poCheckBox = new QCheckBox();
    ThisTreeWidget->setItemWidget(poRecord, 1, poCheckBox);
    poCheckBox->connect(poCheckBox, SIGNAL(stateChanged(int state)), this, SLOT(changechilditemCheckboxStatus(poRecord, state)));

    I'm not very sure whether this is the rite way to do this, but it doesnt seem to work , so I must be doing something wrong. Would appreciate it if someone could point a direction for me to go on. Thanx

    Harpo, newbie

  13. #13
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget question

    Quote Originally Posted by harpo
    I'm not very sure whether this is the rite way to do this, but it doesnt seem to work , so I must be doing something wrong. Would appreciate it if someone could point a direction for me to go on.
    I just implemented a delegate class which do place to the last column some widget ( QToolButton in my case ) and move this column on the first pos. The using of delegates is very good described in Qt documentation. Also you could use
    Qt Code:
    1. void QTreeWidgetItem::setCheckState ( int column, Qt::CheckState state )
    To copy to clipboard, switch view to plain text mode 
    I think it would be better in your case.

  14. #14
    Join Date
    Feb 2006
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget question

    I've solved the problem, thanks a lot for the input

Similar Threads

  1. QTreeWidget Custom Editor Question
    By chaoticbob in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2008, 07:06
  2. hello,i want to ask a question about qtreewidget?
    By frednuaa in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2008, 13:30
  3. QTreeWidget question
    By ClamsTheCat in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2008, 20:48
  4. QTreeWidget Question
    By BatteryCell in forum Qt Programming
    Replies: 2
    Last Post: 22nd June 2007, 22:44
  5. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32

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.