Results 1 to 3 of 3

Thread: QTreeView and unwanted scrollbar

  1. #1

    Default QTreeView and unwanted scrollbar

    Hi,
    I have a QTreeView that is populated by setModel:

    Qt Code:
    1. model = new MyModel();
    2. myTreeView->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    When I do this the first time, my model is empty, but is subsequently filled.
    The tree view appears as expected.

    However, when I do this with a model that is not empty, I find that unwanted
    and unneccesary horizontal scrollbars are appearing - the row is not wide
    enough to warrant one.

    If I do:
    Qt Code:
    1. myTreeView->resizeColumnToContents(0);
    To copy to clipboard, switch view to plain text mode 

    the scrollbars go away, but I don't want to have to force my larger items to be
    fully open. Any pointers?
    Thanks in advance

  2. #2
    Join Date
    Mar 2008
    Location
    Marslev, Denmark
    Posts
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QTreeView and unwanted scrollbar

    This is pretty difficult to get right. Qt doesn't do automatic sizing of the column widths on open, so you have to do it yourself. Basically, you have to do the resizeColumnToContents on all the columns, and then distribute the remaining space to the columns you want. You can call setStretchLastSection on your horizontal header, for something that does a remotely reasonable thing.

    I would also suggest to you to save the state of the headers so the user doesn't have to resize the views to his liking every time.
    Bo Thorsen, Viking Software
    Qt applications on Linux and Windows

  3. #3

    Default Re: QTreeView and unwanted scrollbar

    Hi, thanks for your answer. One question though, how come it does what I want for the case where model is empty upon setModel, but something different for when the model is subsequently populated?
    Thanks,

Similar Threads

  1. QGraphicsView unwanted margin
    By hheld in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2011, 18:16
  2. QPlastiqueStyle and QTreeView Scrollbar
    By yazwas in forum Qt Programming
    Replies: 0
    Last Post: 14th November 2009, 00:03
  3. Replies: 4
    Last Post: 16th October 2009, 10:19
  4. Unwanted padding on QWidget
    By etru1927 in forum Qt Programming
    Replies: 4
    Last Post: 7th August 2008, 08:42
  5. QMdiArea unwanted actvation
    By fullmetalcoder in forum Qt Programming
    Replies: 7
    Last Post: 12th November 2007, 08:09

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.