Results 1 to 5 of 5

Thread: How to convert a horizontal model to a vertical model?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    2

    Default How to convert a horizontal model to a vertical model?

    Hi,

    I have a horizontal table model with [1 row x 7 columns].
    I'd like to make a proxy model to it, which will be a vertical [7 rows x 1 column] model.
    Someone suggests me to use QIdentityProxyModel, but I have no idea further.
    Would somebody please give me advises?
    Many thanks in advance.

    Jong Hwang

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to convert a horizontal model to a vertical model?

    Re implement columnCount, rowCount, and data functions of your inherited qidentityproxyModel...
    Qt Code:
    1. int MyIdentityProxyModel::columnCount(...) const {
    2. return sourceModel()->rowCount();
    3. }
    4. int MyIdentityProxyModel::rowCount(...) const {
    5. return sourceModel()->columnCount();
    6. }
    7. QVariant MyIdentityProxyModel::data(const QModelIndex &idx, int role)
    8. {
    9. if (role != Qt::DisplayRole) return QIdentityProxyModel::data(idx, role);
    10. QModelIndex srcIdx = sourceModel()->index(idx.column(), idx.role());
    11. return srcIdx.data();
    12. }
    To copy to clipboard, switch view to plain text mode 
    This is not tested code. But just to give you an idea.

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

    The Lion (5th June 2013)

  4. #3
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    2

    Default Re: How to convert a horizontal model to a vertical model?

    Thank you very much for your quick and helpful info.

    Jong Hwang

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to convert a horizontal model to a vertical model?

    Example in the wiki: [wiki]Transpose proxy model[/wiki]

  6. The following user says thank you to ChrisW67 for this useful post:

    The Lion (5th June 2013)

  7. #5
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    2

    Smile Re: How to convert a horizontal model to a vertical model?

    Thank you very much.
    I was about to pull my hair out.
    You saved my life.

Similar Threads

  1. Replies: 9
    Last Post: 14th February 2013, 20:39
  2. Event handlers for QTableView model / selection model.
    By hickscorp in forum Qt Programming
    Replies: 2
    Last Post: 8th July 2011, 18:57
  3. Using model indices in complex model item relationships
    By hackerNovitiate in forum Newbie
    Replies: 0
    Last Post: 29th June 2011, 15:30
  4. Replies: 1
    Last Post: 24th February 2011, 06:54
  5. Model/view, apply a filter on model
    By remy_david in forum Qt Programming
    Replies: 4
    Last Post: 4th February 2011, 18:13

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.