Results 1 to 6 of 6

Thread: [Qtreeview] How to let the child content always top display

  1. #1
    Join Date
    Mar 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default [Qtreeview] How to let the child content always top display

    See from the left part picture, the child content is hided, I need adjust the column width to show out the child content.

    So I want to know how to show the whole content of child without adjust the column width.

    Untitled.jpg
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [Qtreeview] How to let the child content always top display

    Have you tried QHeaderView::setSectionResizeMode()?

    Cheers,
    _

  3. #3
    Join Date
    Mar 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: [Qtreeview] How to let the child content always top display

    Quote Originally Posted by lovelyld View Post
    See from the left part picture, the child content is hided, I need adjust the column width to show out the child content.

    So I want to know how to show the whole content of child without adjust the column width.

    Untitled.jpg
    Hi, thanks for your reply. I used the setSectionResizeMode() in the follow Capture.PNGway. The first column width will adjust automatically. But what I want is, the column width of the parent item not change, just change the child item column width. Like this picture show. The child content length is longer than the parent column width. How can I achieve this?

    t->header()->setSectionResizeMode(QHeaderView::ResizeToContent s);

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [Qtreeview] How to let the child content always top display

    Ah, you don't want to change the width of a column, you want certain cells to span more than a column.

    Might be possible with a custom delegate on the first column.
    When it is handling a top level entry it would do normal drawing, when handling a sub item it would ignore the cell rectangle's width.

    Cheers,
    _

  5. #5
    Join Date
    Mar 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: [Qtreeview] How to let the child content always top display

    Quote Originally Posted by anda_skoa View Post
    Ah, you don't want to change the width of a column, you want certain cells to span more than a column.

    Might be possible with a custom delegate on the first column.
    When it is handling a top level entry it would do normal drawing, when handling a sub item it would ignore the cell rectangle's width.

    Cheers,
    _
    Hi, As your suggestion, I implement a delegate in follow way.

    Qt Code:
    1. void ColumnDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
    2. const QModelIndex &index) const
    3. {
    4. if(index.parent().isValid())
    5. {
    6. QString text = index.model()->data(index, Qt::DisplayRole).toString();
    7. QStyleOptionViewItem myOption = option;
    8. myOption.rect.adjust(0,0,500,0);
    9. myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
    10. QApplication::style()->drawItemText ( painter, myOption.rect , myOption.displayAlignment, QApplication::palette(), true,text );
    11. }
    12. else
    13. {
    14. QStyledItemDelegate::paint(painter, option, index);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    this solve my previous problem, but I meet another problem, when I adjust second column width it will hide the content of child item. how to solve this problem, see the attachment.

    Untitled1.jpg
    Last edited by anda_skoa; 2nd April 2019 at 10:22. Reason: missing [code] tags

  6. #6
    Join Date
    Mar 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: [Qtreeview] How to let the child content always top display

    Quote Originally Posted by anda_skoa View Post
    Ah, you don't want to change the width of a column, you want certain cells to span more than a column.

    Might be possible with a custom delegate on the first column.
    When it is handling a top level entry it would do normal drawing, when handling a sub item it would ignore the cell rectangle's width.

    Cheers,
    _
    solve this problem by using the section resize signals of Qheaderview, in the slot I hide the first line and show it again to trigger the first column repaint()

Similar Threads

  1. Replies: 0
    Last Post: 12th April 2010, 22:41
  2. Designing the display content of a push button
    By cookie1909 in forum Newbie
    Replies: 4
    Last Post: 16th April 2009, 23:24
  3. QTreeView PARENT & CHILD
    By zeeb100 in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2009, 15:53
  4. Replies: 2
    Last Post: 8th January 2009, 01:49
  5. Replies: 1
    Last Post: 16th January 2008, 12:48

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.