Results 1 to 7 of 7

Thread: QTableWidget (resizing rows, turning off selection, etc.)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    29
    Thanks
    3

    Default Re: QTableWidget (resizing rows, turning off selection, etc.)

    I tried your code verbatim, and still got no action. Tried to output something to cout as well, denoting that it was inside the overridden function, but got nothing. My guess is that it's not being called.

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

    Post Re: QTableWidget (resizing rows, turning off selection, etc.)

    Here is a standalone example. let me know if it works for you.

    Qt Code:
    1. #include <QApplication>
    2. #include <QTableWidget>
    3.  
    4. class MyTableWidget : public QTableWidget
    5. {
    6. public:
    7. MyTableWidget (int r, int c, QWidget *parent = 0)
    8. : QTableWidget(r,c,parent)
    9. {
    10. }
    11. protected:
    12. int sizeHintForRow(int row) const
    13. {
    14. return 100;
    15. }
    16. };
    17.  
    18. int main(int argc, char* argv[])
    19. {
    20. QApplication app(argc, argv);
    21. MyTableWidget *tbl = new MyTableWidget( 10, 8 );
    22. tbl->setSelectionMode( QAbstractItemView::NoSelection );
    23. tbl->setEditTriggers(QAbstractItemView::NoEditTriggers);
    24. tbl->setFocusPolicy( Qt::NoFocus );
    25.  
    26. for ( int r = 0; r < 10; r++)
    27. for ( int c = 0; c < 8; c++ )
    28. tbl->setItem( r, c, new QTableWidgetItem( QString::number(r+1)+" "+QString::number(c+1)) );
    29.  
    30. tbl->resizeRowsToContents();
    31. tbl->show();
    32. return app.exec();
    33. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2007
    Posts
    29
    Thanks
    3

    Default Re: QTableWidget (resizing rows, turning off selection, etc.)

    Well, I'm never resizing the rows... only making them. That's the first major difference I see between my code and yours. As before, I will continually be adding rows (maybe up to 1000). Running a routine that resizes them all doesn't seem efficient in the least.

Similar Threads

  1. QTableWidget Sorting Multiple Selection
    By rhiacasta in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2006, 21:05
  2. 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
  •  
Qt is a trademark of The Qt Company.