Results 1 to 7 of 7

Thread: Different number of columns in each row

  1. #1
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Different number of columns in each row

    Hello all,

    Is it possible to create QTreeWidget or QTreeView element with different number of columns in each row? I need to create widget that behaves as a tree (can collapse and expand) but have different widget in each row. I believe that row widgets can be represented as a cells, but number of columns in each row may be vary.

    Is there any model to represent create such tree?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Different number of columns in each row

    no.
    with the signature
    Qt Code:
    1. int columnCount(const QModelIndex& parent)
    To copy to clipboard, switch view to plain text mode 
    you are forced to have the same number of colums for all rows of a parent index.
    (Moreover, the views don't support something like that.)

    You can create a view that 'stops' at the first column to return an empty QVariant() for the Qt:isplayRole. That is *your* convention then...

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

    1111 (3rd March 2009)

  4. #3
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: Different number of columns in each row

    But is it possible to put QWidget instead of item data in the tree?

    I mean QTreeView has same structure and only one column, but each line in the QTreeView is a custom widget.

  5. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Different number of columns in each row

    Just wondering... is it a good idea to have all your cells as widgets ?
    I dont think so... there must be some other way to achieve your goal...

  6. #5
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Different number of columns in each row

    Quote Originally Posted by aamer4yu View Post
    Just wondering... is it a good idea to have all your cells as widgets ?
    I dont think so... there must be some other way to achieve your goal...
    But are common widgets do the same? I thought QTreeView and QTableView use QLabel and QLineEdit to show information on the screen.

  7. #6
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Different number of columns in each row

    no, they do not.
    they use "delegates" to render the data. they only create widgets for editing data.

    see QItemDelegate, model-view-delegate

  8. The following user says thank you to caduel for this useful post:

    1111 (9th March 2009)

  9. #7
    Join Date
    Nov 2008
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Different number of columns in each row

    Thanks for tips.

    It looks like, this is the way how I should implement my widgets.

    There is paint() function that must be implemented if you subclass delegate class. This function must manually draw a widget, but my widget is a splitter that contains several QLabels inside. Is there any function or class that helps me to draw it fast?

    I know there are drawControl(), drawPrimitive() and drawComplex() functions that can draw some widgets automatically. But non of them can draw splitter for instance or calculate layout sizes. However, if you create a widget and insert it into window, application automatically draw it, so application use some functions for calculating components size and location.

    To sum it up my question is, are there any functions that I can use inside paint() function in my delegate class, that can automatically draw composite widgets?


    Any tips are appreciated.

Similar Threads

  1. Table with number of columns depending on row?
    By Arghargh in forum Qt Programming
    Replies: 3
    Last Post: 29th May 2008, 14:03
  2. How can I get the number of columns in QSqlQuery.
    By fengtian.we in forum Qt Programming
    Replies: 1
    Last Post: 21st May 2007, 12:04
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  4. xml - get number of columns
    By wind in forum Newbie
    Replies: 3
    Last Post: 1st November 2006, 11:38
  5. Replies: 6
    Last Post: 5th March 2006, 22:05

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.