Results 1 to 6 of 6

Thread: QTableView and column resize problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView and column resize problem

    Your example does work for me. However, the difference is that I need for column 2 to show the elides and column 4 to be hidden. What I'm doing is more:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6.  
    7. model.setStringList(QStringList() << "Very very long line of text"
    8. << "Very very long line of text"
    9. << "short text"
    10. << "short text");
    11.  
    12. QTableView view;
    13. view.setModel(&model);
    14. view.horizontalHeader()->setResizeMode( 0, QHeaderView::Interactive);
    15. view.horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch );
    16. view.setSectionHidden( 2, true );
    17. view.setSectionHidden( 3, true );
    18. view.show();
    19.  
    20. return a.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 

    For me this approach (I'm using c++ not python) the table view INSISTS on wrapping the contents of the column. If I don't stretch the second column, the text is still wrapped, but the user can resize the column. However, it has a huge block of dead space. ( there is a reason that those columns are hidden. )

    It's looking like my only option is to handle the elide myself, in the column's delegate.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableView and column resize problem

    Hi,

    you code is not working, and for what you trying to test you need a proper model! So here we go
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6.  
    7.  
    8. QStandardItemModel model(4, 4);
    9. for (int row = 0; row < 4; ++row) {
    10. for (int column = 0; column < 4; ++column) {
    11. QStandardItem *item = new QStandardItem(QString("(%1) Very very long line of text").arg(column));
    12. model.setItem(row, column, item);
    13. }
    14. }
    15.  
    16. QTableView view;
    17. view.setModel(&model);
    18. view.horizontalHeader()->setResizeMode( 0, QHeaderView::Interactive);
    19. view.horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch );
    20. view.horizontalHeader()->setSectionHidden( 2, true );
    21. view.horizontalHeader()->setSectionHidden( 3, true );
    22. view.show();
    23.  
    24. return a.exec();
    25. }
    To copy to clipboard, switch view to plain text mode 
    This elides all like one suppose.

Similar Threads

  1. QTableView with a column of images
    By elanari in forum Qt Programming
    Replies: 13
    Last Post: 7th February 2012, 12:25
  2. Qtableview column get increasing
    By maarvi in forum Newbie
    Replies: 0
    Last Post: 28th June 2011, 19:21
  3. Replies: 1
    Last Post: 8th May 2011, 23:13
  4. Replies: 2
    Last Post: 18th October 2010, 17:58
  5. Replies: 1
    Last Post: 1st May 2010, 23:03

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
  •  
Qt is a trademark of The Qt Company.