Results 1 to 3 of 3

Thread: QTreeWidget/QListWidget: Edit gives QLineEdit too little on the height

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation QTreeWidget/QListWidget: Edit gives QLineEdit too little on the height

    Hi,
    Using QTreeWidget or QListWidget I have too little height when I edit items, it's surely a common issue, giving the rename hard to do.
    What is the best way to solve this issue ? Because set the size manually is maybe an option but Qt has something automatic to solve that ?
    Thanks

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTreeWidget/QListWidget: Edit gives QLineEdit too little on the height

    No automatic resize while editing, have to do it explicitly.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeWidget/QListWidget: Edit gives QLineEdit too little on the height

    Apparently the issue which cause this little edit line edit is because I use padding in QLineEdit in the stylesheet :
    Qt Code:
    1. {
    2. ...
    3. padding: 2px;
    4. }
    To copy to clipboard, switch view to plain text mode 
    Looks like a bug from Qt to not compute the size correctly from QLineEdit.
    Where is the best place to set the size manually or maybe possible to create the editor QLineEdit widget manually with a lookup on the actual style of QLineEdit ?
    I tried to change the sizeHint of the item in the QStyledItemDelegate but I only got bigger item, the editor widget is not resized.

    EDIT:
    Here the hack found to avoid the Qt issue :
    Qt Code:
    1. virtual void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const override
    2. {
    3. // Init the item option.
    4. QStyleOptionViewItem itemOption = option;
    5. initStyleOption( &itemOption, index );
    6.  
    7. // Move the rect top value to avoid the height issue, 1px of padding on the top and bottom.
    8. QRect Geom = QApplication::style()->subElementRect( QStyle::SE_ItemViewItemText, &itemOption, editor );
    9. Geom.setTop( Geom.top() - 1 );
    10.  
    11. // Set the geometry.
    12. editor->setGeometry( Geom );
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Alundra; 31st March 2017 at 16:41.

Similar Threads

  1. QTreeWidget minimum height
    By Alundra in forum Qt Programming
    Replies: 11
    Last Post: 19th November 2014, 17:51
  2. How to make a QTreeWidget readjust row height!
    By Berryblue031 in forum Qt Programming
    Replies: 4
    Last Post: 29th May 2013, 18:31
  3. Replies: 0
    Last Post: 28th October 2011, 09:28
  4. Determining the height of an item in a QListWidget
    By negritot in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2009, 19:18

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.