Solved turn off elide in column of qtablewidget
-
@eyllanesc
How do we know whichQStyleOptionViewItem
things to do ininitStyleOption()
versus what @sawarsi tried to do in thepaint()
override?Ah, I see it says:
When reimplementing paint in a subclass. Use the initStyleOption() to set up the option in the same way as the QStyledItemDelegate.
but not sure I understand "in the same way as"?
Given that
paint()
takes aconst QStyleOptionViewItem &option
, are you not supposed to alter it and pass it on as he did? Is theoption
intended to be read-only at this stage? -
paint receives the option but then modifies it by invoking the initStyleOption. If you want to know how a class works then it is better to check the source code: https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/itemviews/qstyleditemdelegate.cpp?h=dev#n377
void QStyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_ASSERT(index.isValid()); QStyleOptionViewItem opt = option; initStyleOption(&opt, index); // <--- update option const QWidget *widget = QStyledItemDelegatePrivate::widget(option); QStyle *style = widget ? widget->style() : QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget); }
@sawarsi you should not modify the paint method
-
@eyllanesc yes i removed the paint function entirely and used your suggestion and i am still seeing ellipses.
-
@sawarsi Could you provide a minimum reproducible example? Maybe the error is another.
-
@eyllanesc ok i will see if i can setup a simple example
-
@sawarsi Also before you start put a breakpoint/debug message into your code to make 100% sure your override is getting called.
-
@JonB yes it is getting hit.
-
@JonB what i did notice in the debugger is that each of the cells in the second column i have put in text but when i print the text in initStyleOption then it is always "".
so is setItemDelegateForColumn(1,...) the correct way of doing this?
-
@sawarsi nevermind it was my fault your suggestion is flawless.
-
@eyllanesc thanks for the help.
-
@sawarsi one thing i did notice is that this works just fine in linux but fails on windows any hints?
-
@eyllanesc one thing i did notice is that this works just fine in linux but fails on windows any hints?
-
@sawarsi As can be seen in the source code of "paint", the QStyle is used to make the painting, so the style probably does not use some option properties, a possible solution is to use another style like:
app.setStyle("fusion" );
-
@eyllanesc i tried all the Windows styles (Windows and Fusion) and neither worked it may be that Windows mandates ellipses. i am not sure anyway, i am going to mark this solved.
-
@eyllanesc I admire you a lot. This is one of the best ways for an informed person to respond to a question. Anyone asking question is usually confused and an illustrative answer is the best. I notice you always go out of your way to give a practical example. Honestly if you have a class where you teach students, I would love to be one of your students.
Thank you very much.