Results 1 to 3 of 3

Thread: Resize rows and cols in a Tablewidget

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Question Resize rows and cols in a Tablewidget

    I'm trying to programming a tablewidget with 50 rows (maximum) and i want that table resize its height to number of rows if rows are less than 6, and if rows are more than 5 table fixed its height to 6 rows (+header).

    My code is (I dont know how to put this as a code windows, as i can see in other post):

    Qt Code:
    1. void Sheet::resize()
    2. {
    3. tabla->resizeRowsToContents();
    4. int rows=tabla->rowCount();
    5. int rowalt=tabla->rowHeight(0);
    6. int height;
    7. QScrollBar *Hscrollbar=tabla->horizontalScrollBar();
    8. QHeaderView *Hheader=tabla->horizontalHeader();
    9. if (Hheader->count()<4)
    10. Hheader->setResizeMode(QHeaderView::Stretch);
    11.  
    12. if (rows<6){
    13. height=rows*rowalt+Hheader->height();
    14. }else{
    15. height=6*rowalt+Hheader->height();//+tabla->horizontalHeader()->heigth();
    16. }
    17. if (!Hscrollbar->isVisible())height=height + Hscrollbar->height();
    18. tabla->setMinimumHeight(height);
    19. }
    To copy to clipboard, switch view to plain text mode 
    But sometimes resize ok, sometimes bad (n-1 rows), sometimes n and a half rows.....

    What happend?

    Thanks
    Last edited by zorro68; 11th February 2007 at 12:31.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Resize rows and cols in a Tablewidger

    Quote Originally Posted by zorro68 View Post
    My code is (I dont know how to put this as a code windows, as i can see in other post)
    Highlight the code and select the "#" from the editor, or wrap it inside [ code ]-tags by hand (without the spaces):
    [ code ]
    void func() {
    }
    [ /code ]
    Please do so, it will make the code much more readable..
    J-P Nurmi

  3. #3
    Join Date
    Jan 2007
    Posts
    95
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: Resize rows and cols in a Tablewidget

    Thanks jpn

    I have made some changes to the code, but dont work correctly. Help please...

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.