Results 1 to 1 of 1

Thread: QTreeView::setHeaderHidden corrupts column width

  1. #1
    Join Date
    Dec 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTreeView::setHeaderHidden corrupts column width

    A simple rectangular table.
    View inherits from QTreeView.
    Model inherits from QAbstractTableModel.
    There are checkboxes in column one (Model::data responds to role==Qt::CheckStateRole if col==1).
    Model::headerData returns the empty default QVariant for col==1.
    View::sizeHintForColumn returns fontMetrics().width('m') for col==1.

    Everything works like a charm until I activate View::setHeaderHidden(<someCondition>).
    Whenever <someCondition> becomes false and the header reappears, column 1 shrinks by about 50%, and the check boxes are clipped.


    Added after 1 11 minutes:


    Found the answer: As long as the header is visible, the fontMetrics() reference in View::sizeHintForColumn returns the header font, which is wider than the ordinary font used in the table cells.
    Last edited by jwu; 16th January 2018 at 15:10.

Similar Threads

  1. Replies: 0
    Last Post: 5th January 2016, 18:41
  2. How to resize column width
    By anbu01 in forum Newbie
    Replies: 0
    Last Post: 11th August 2014, 14:05
  3. QTableWidget Default width of row and column
    By sagirahmed in forum Newbie
    Replies: 4
    Last Post: 11th October 2010, 04:01
  4. QTableWidget column width and resizing
    By shooogun in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2008, 22:31
  5. set Column Width in QTreeWidget?
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2007, 08:12

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.