Results 1 to 4 of 4

Thread: Cut the displayed text in QTreeWidgetItem

  1. #1
    Join Date
    Mar 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Cut the displayed text in QTreeWidgetItem

    Hi all,

    I am trying to avoid a horizontal scrollbar in QTreeWidget by restricting the text of the items to some fixed number of characters (let's say 25). The functionality I need is to restrict the _displayed_ name only, keeping the original name in the case the item text is being edited. Also, the original text can be displayed on mouse hover, but this is simply solvable by QTreeWidgetItem::setToolTip().
    Is there any standard way to do something like this?

    Thank you.

    QStringList sEntryList;
    sEntryList << "Some text here which does not need to be displayed fully, making the QTreeWidget horizontally scrollable";
    QTreeWidgetItem* const pEntryItem = new QTreeWidgetItem(1, 0, 5, this, sEntryList);
    pEntryItem->setFlags(pEntryItem->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
    pEntryItem->setToolTip("This text here can be displayed on mouse hover event");

  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: Cut the displayed text in QTreeWidgetItem

    Is there any standard way to do something like this?
    No, there is no standard way to do so. You will need to write something for yourself.
    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
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Cut the displayed text in QTreeWidgetItem

    Quote Originally Posted by Moon View Post
    I am trying to avoid a horizontal scrollbar in QTreeWidget by restricting the text of the items to some fixed number of characters (let's say 25).
    You can simply disable horizontal scrollbar. QAbstractScrollArea::setHorizontalScrollBarPolicy( )

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Cut the displayed text in QTreeWidgetItem

    Unless my memory is failing, overly long DisplayRole text will be truncated by default if the column is not wide enough. Don't set the view to automatically resize the columns to the content. Then put the desired size on the columns, optionally stretch the a section, and you are done.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

Similar Threads

  1. No text displayed in widgits after installing Qt on Sun Solaras 8
    By rajyadav in forum Installation and Deployment
    Replies: 0
    Last Post: 11th April 2012, 00:05
  2. QTreeWidgetItem text color
    By Arthur in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2009, 16:59
  3. set color in QTreeWidgetItem text
    By mattia in forum Newbie
    Replies: 2
    Last Post: 7th January 2008, 09:06
  4. formatted text in QTreeWidgetItem
    By swiety in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2007, 16:26
  5. QTreeWidgetItem setting color for the text
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2007, 17:22

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.