Results 1 to 4 of 4

Thread: Table with number of columns depending on row?

  1. #1
    Join Date
    Jul 2007
    Location
    Germany
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Table with number of columns depending on row?

    Hello,

    finally after a year just reading my first post

    I'm using Qt 4.3 and I want to create a table (QTableView) with a different number of columns per row, for example
    Row 0: Col0 Col1
    Row 1: Col0
    Row 2: Col0 Col1 Col2

    Is this even possible with a QTableView, or would I have to implement my own custom view?

    If it is possible, how can I access the row number? I thought I could use a custom model and return different values in columnCount() depending on the row, but the ModelIndex just returns -1 as row number.

    Thanks in advance,

    Arghargh

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Table with number of columns depending on row?

    The QModelIndex argument of columnCount() doesn't mean anything in flat models, so the short answer to your question is no.
    However you can reimplement QAbstractItemModel::flags() to differentiate empty cells from valid ones(returning 0 means a cell is not enabled, not selectable and not editable).
    Last edited by spud; 29th May 2008 at 12:15. Reason: spelling error

  3. #3
    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: Table with number of columns depending on row?

    Notice also QTableView::setSpan().
    J-P Nurmi

  4. #4
    Join Date
    Jul 2007
    Location
    Germany
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Table with number of columns depending on row?

    Thank you for the answers.
    At the moment I use a combination of your suggestions, a non-editable spanning widget with a BackgroundRole for the correct (grey) background color. I works fine, I just thought the code was a little ugly so I'm looking for another way to accomplish the special table, but I don't think a custom view would be worth the effort.

    Arghargh

Similar Threads

  1. How can I get the number of columns in QSqlQuery.
    By fengtian.we in forum Qt Programming
    Replies: 1
    Last Post: 21st May 2007, 11:04
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. xml - get number of columns
    By wind in forum Newbie
    Replies: 3
    Last Post: 1st November 2006, 10:38
  4. Replies: 6
    Last Post: 5th March 2006, 21:05

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.