Results 1 to 6 of 6

Thread: QHeaderView and autoResizeToContent

  1. #1
    Join Date
    Jul 2012
    Posts
    20
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4

    Default QHeaderView and autoResizeToContent

    I have a QTableView. And I use following code:
    Qt Code:
    1. ui->tblCivilianFlightPlan->setModel (mModel);
    2. ui->tblCivilianFlightPlan->resizeColumnsToContents();
    3. ui->tblCivilianFlightPlan->horizontalHeader()->setStretchLastSection(true);
    To copy to clipboard, switch view to plain text mode 

    Content of header display ok. But I use multi-language for my app, and when I switch language, the content doesn't show completely.
    How can I make the header auto resizing to content ?

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QHeaderView and autoResizeToContent

    By reading the documentation for QHeaderView.

  3. #3
    Join Date
    Aug 2012
    Location
    Montreal
    Posts
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHeaderView and autoResizeToContent

    You have two choices. Like yeye_olive said, if you had read the documentation for QHeaderView, you would know that you can set QHeaderView::setResizeMode(QHeaderView::ResizeToCo ntents) to automatically resize for you. But if you do that you can't change the size of the columns to whatever you want. So what I would do is to re-call resizeColumnsToCentents() after you have processed the QEvent::LanguageChange event.

  4. #4
    Join Date
    Jul 2012
    Posts
    20
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4

    Default Re: QHeaderView and autoResizeToContent

    I'd read the document and I know QHeaderView::setResizeMode() but I dont like it 'cause I cant change the size of the columns.
    So, re-call resizeColumnsToContent() may be a better way.
    But, problem is: I cant find the thing resizeColumnsToContent() in document QHeaderView (and QAbstractItemView). How can I find this ?

  5. #5
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QHeaderView and autoResizeToContent

    Quote Originally Posted by vhptt View Post
    But, problem is: I cant find the thing resizeColumnsToContent() in document QHeaderView (and QAbstractItemView). How can I find this ?
    You have got to be kidding us; just read your first post above.

    Note that this will resize all columns, not just those which are not large enough.

  6. #6
    Join Date
    Jul 2012
    Posts
    20
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4

    Default Re: QHeaderView and autoResizeToContent

    I'm not kidding. Maybe this is a stupid question, so plz help me.
    Did you mean " just read your first post above." about: ui->tblCivilianFlightPlan->resizeColumnsToContents(); ???
    But, My question is about function resizeColumnsToContent() of QHeaderView, not for QTableView. Or I'm using wrong word about size of section of header (my english is not good ).
    In addition, I have trouble with tab size - QTabWidget too T___T (after switching language, tabwidget does not show completely tabText).

Similar Threads

  1. QHeaderView with QMenu
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 11th June 2010, 17:07
  2. QHeaderView saveState()
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 26th December 2009, 15:46
  3. QHeaderView
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 25th December 2009, 20:42
  4. QHeaderView and its size
    By area51 in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2009, 08:26
  5. QHeaderView
    By gyre in forum Qt Tools
    Replies: 1
    Last Post: 25th September 2007, 16:35

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.