Results 1 to 2 of 2

Thread: QHeaderView and its size

  1. #1
    Join Date
    Oct 2008
    Location
    Belgium
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QHeaderView and its size

    Hi,

    I'm using a QStandardItemModel with QStandardItems to fill a QTableView. (Qt 4.5.2 on Debian Linux)

    Qt Code:
    1. QTableView *table = new QTableView();
    2. QStandardItemModel *model = new QStandardItemModel(num_rows, num_cols);
    3.  
    4. //add a header for column 0
    5. QStandardItem *header_item = new QStandardItem("Some Title");
    6. model->setHorizontalHeaderItem(0, header_item);
    7.  
    8. //add more headers and items to the model.....
    9.  
    10. //now let the columns resize to fit their contents
    11. table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
    12.  
    13. table->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    The problem occurs when I set the size of the columns to stretch automatically to its contents, but then the content of the headers itself does not fit.
    It seems only the contents of the actual data rows are used for stretching.

    How can I stretch the horizontal headers in a way that it will also fit the text inside the headers?
    Note that the text inside the headers are displayed in a slightly larger and bold font.

    The same things happen when I use: table->resizeColumnToContents(0);

    Thank you in advance
    Last edited by area51; 8th October 2009 at 16:56.

  2. #2
    Join Date
    Oct 2008
    Location
    Belgium
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QHeaderView and its size

    Problem spotted... ;-)

    The header sections in my previous post are styled with qss, it all works fine, however....

    Qt Code:
    1. QHeaderView::section {
    2. background-color: white;
    3. color: black;
    4. font: bold 12px;
    5. border: 1px solid black;
    6. /* height: 20px; */
    7. }
    To copy to clipboard, switch view to plain text mode 

    First, I had set the height property for a header section, but somehow it caused the wrong calculations for stretching the sections correctly.

    Is this expected behavior? Or might it be a bug?
    Last edited by area51; 9th October 2009 at 08:43.

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.