QTreeWidgetItem sizeHint returning QSize(-1,-1)
-
The title says it all.... anybody know why I'm getting -1 for the sizeHint for a column of a QTreeWidgetItem?
-
I did find this:
http://doc.qt.io/qt-5/qabstractitemview.html#sizeHintForColumn
However QTreeWidgetItem has its own sizeHint function so I assume it would work regardless of the model... -
Hi,
What do you have in the model currently ? When are you calling that function ?
-
Currently I'm using a QTreeWidget populated with QTreeWidgetItems. I've tried calling the sizeHint function at different places, after the item has been set up with its text and other column data and also after the QTreeWidget has been completely set up.
-
And visible ?
-
The second call above mentioned was called after calling show() on the widget containing the scroll area and treewidget. I just added
qDebug() << "show" << sourceFilesLeft->sizeHint(0) << sourceFilesLeft->sizeHint(1);
to a slot called realtime from a checkbox and still getting this:
show QSize(-1, -1) QSize(-1, -1)
-
How are you using sourceFilesLeft exactly ?
-
I've tried the sizeHint() for various columns on various QTreeWidgetItems all with the same results. sourceFilesLeft is just a top-level QTreeWidgetItem for one of the QTreeWidgets. I've also tried sizeHint() on my QTreeWidgetItem subclass TreeFileDirItem with the same results.
-
I created a sample project and got the same results with stripped down code. Here it is if you could take a look:
https://www.dropbox.com/s/9v4irn1bvuptxmy/treetest2.zip?dl=0
Click the bullets in the upper right then download...
Thanks -
I am using Qt Creator 4.0.0 with Qt 5.6.0 if that matters....
-
Ok, after having re-check the documentation and the code. That method returns the value you set for it thus since you never gave a size hint to start with you'll get the default value you are currently getting.
-
Do you know if there's any way to get the ideal width for a QTreeWidgetItem so I can tell if it doesn't fit in the column? I just want to have a popup that displays the full column contents when the contents don't fit in the column.
-
Here it says:
Sets the size hint for the tree item in the given column to be size. If no size hint is set, the item delegate will compute the size hint based on the item data.
http://doc.qt.io/qt-5/qtreewidgetitem.html#setSizeHint
Doesn't that sound like it should return an ideal sizehint based on the size of the column data or text?
-
The delegate will do the math, but it won't change the content of the model.
-
Doesn't that imply sizehint should return an ideal size for the column of a qtreewidgetitem? Which should be adequate for my purposes.
-
What is exactly your purpose ?
-
I just want to set a tooltip for qtreewidgetitems whose text does not fit in the column.
-
So you would like the column to resize so your tooltip fits in ?
-
A tooltip is where you hover the mouse over an item and a text window pops up right? So if the text doesn't fit in the column the user can hover over the qtreewidgetitem column and see the full text without resizing the column.
-
So, in fact, you would like to show the full content of a cell in a QToolTip ?
1/27