Results 1 to 4 of 4

Thread: QTreeWidget (Row Check, Custom Sort)

  1. #1
    Join Date
    Sep 2007
    Posts
    14
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QTreeWidget (Row Check, Custom Sort)

    Hello,

    I am trying to do the following three things with an application much like the one attached:

    1) Attach the check box to the full table row, as opposed to just an item in the table - Right now, it moves with the column if the user changes the column order. Is it possible for the check to always be left-most widget?

    2) Custom sort the IP address field - Can i make a custom sort routine for a single column of the table, or use one of the other item roles so I can have it sort directly on QHostAddress data, instead of the string data? (as in "192.168.0.1, 192.168.0.2, 192.168.0.101, 192.168.0.201" instead of "192.168.0.1, 192.168.0.101, 192.168.0.2, 192.168.0.201")

    3) Is there a way to quickly automate the hiding and showing of individual columns, the the common context menu on most file explorers' detail view?

    Thank you for your assistance.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget (Row Check, Custom Sort)

    You can control the sort order by reimplementing QTreeWidgetItem::operator<().

  3. The following user says thank you to jacek for this useful post:

    AaronMK (8th January 2008)

  4. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget (Row Check, Custom Sort)

    Quote Originally Posted by jacek View Post
    You can control the sort order by reimplementing QTreeWidgetItem:perator<().
    Just keep in mind that a alphanumeric sort will be performed. To achieve what you want you will have to sort on each IP byte. So if you have the IP: 194.102.98.10 then you'll have to split it in 4 bytes: 194, 102, 98 and 10. You must do this for all IP's; the 4th byte will have the highest priority, while the 1st byte the lowest.

    Attach the check box to the full table row, as opposed to just an item in the table - Right now, it moves with the column if the user changes the column order. Is it possible for the check to always be left-most widget?
    Create another column(first column) which will contain only the check box.

    Is there a way to quickly automate the hiding and showing of individual columns, the the common context menu on most file explorers' detail view?
    After briefly looking at your code, it seems to me that it is not easy to extended it in the direction you want.
    You must always recreate the items after hiding the columns.

    Bottom line is that in a long run you'd be better if you use a QTreeView + some model.
    For hding/showing columns you can easily use QHeaderView::hideSection() and QHeaderView::showSection().

  5. The following user says thank you to marcel for this useful post:

    AaronMK (8th January 2008)

  6. #4
    Join Date
    Sep 2007
    Posts
    14
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTreeWidget (Row Check, Custom Sort)

    Thank you again for your assistance.

    To achieve what you want you will have to sort on each IP byte.
    The QHostAddress::toIPv4Address () method worked well for this.

    After briefly looking at your code, it seems to me that it is not easy to extended it in the direction you want.
    ...
    Bottom line is that in a long run you'd be better if you use a QTreeView + some model.
    Our model in the actual application is pretty deeply entrenched with a shipping date for the next release very near. However, this suggestion pops up so often with QTreeWidget related questions. Moving to Qt's official data model will be a serious consideration for the next release.

    Code with a couple of suggestions implemented attached for reference.
    Attached Files Attached Files

Similar Threads

  1. Custom sort with QTableWidget
    By nicolas44 in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2007, 00:47

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.