Results 1 to 5 of 5

Thread: AutoAdjust columns in a QTreeView

  1. #1
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default AutoAdjust columns in a QTreeView

    How can I make a QTreeView to auto-adjust the wigth of the columns?
    The only thing that I found here is resizeColumnToContents(), but this method will make me call it for every column. Isn't there something else?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: AutoAdjust columns in a QTreeView

    See QHeaderView::setResizeMode() with QHeaderView::ResizeToContents.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: AutoAdjust columns in a QTreeView

    Qt Code:
    1. (self.ui.qtreeview.header()).setResizeMode(3)
    To copy to clipboard, switch view to plain text mode 

    That works great ! But now I have another 2 problems. The first one is that I can't hide one of the columns, I tried with this:
    Qt Code:
    1. index = (self.ui.qtreeview.header()).visualIndex(4)
    2. (self.ui.qtreeview.header()).setSectionHidden(index, True)
    To copy to clipboard, switch view to plain text mode 

    The second problem is that I have some qstandarditems that have really long text, and when the text-column is expanded according to the size of the text, the QTreeView will become... scrollable (horizontally). How can I prevent that?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: AutoAdjust columns in a QTreeView

    Quote Originally Posted by alexandernst View Post
    The second problem is that I have some qstandarditems that have really long text, and when the text-column is expanded according to the size of the text, the QTreeView will become... scrollable (horizontally). How can I prevent that?
    Don't set the resizeMode policy to ResizeToContents for that column (or set it to something else).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: AutoAdjust columns in a QTreeView

    Great,
    Qt Code:
    1. (self.ui.cList.header()).resizeSections(1)
    To copy to clipboard, switch view to plain text mode 
    did the trick perfectlly. I also got the first one. I just had to say to the model that it'll have 5 columns, and then I hidded them with
    Qt Code:
    1. .setSectionHidden(int, True)
    To copy to clipboard, switch view to plain text mode 

    Really thanks wysota!

Similar Threads

  1. QTreeView Fixed column & QTableView
    By jpujolf in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2008, 09:35
  2. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 21:22
  3. Moving columns/hiding columns in QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2007, 16:22
  4. [qt4 & Xp] resize columns of a QTreeView
    By incapacitant in forum Newbie
    Replies: 4
    Last Post: 2nd March 2006, 14:06
  5. Changing the order of columns in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 00:00

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.