QTableWidget elide middle not working as expected
Solved
General and Desktop
-
Hi, I am using Qt 6.5. I have a
QTableWidget
and am trying to set the elide mode toQt::ElideMiddle
but it is not working as expected. For example, if my text is "This is an example of elided text" then with default settings, it appears as "This is an..." but if I useQTableWidget::setTextElideMode(Qt::ElideMiddle)
it appears as "This ... an ..." same happens if I use a custom item delegate:void ElideMiddleDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyleOptionViewItem opt = option; opt.textElideMode = Qt::ElideMiddle; QStyledItemDelegate::paint(painter, opt, index); }
Why am I getting the ellipsis both in the middle and at the end? Is there any way to set it to elide only in the middle?
-
I would guess your QTableWidgetItem has wordWrap set to true (default). This works fine for me:
int main(int argc, char** argv) { QApplication app(argc, argv); QTableWidget tw; tw.setRowCount(1); tw.setColumnCount(1); auto item = new QTableWidgetItem("a very long text which is elided in the middle"); tw.setItem(0, 0, item); tw.setTextElideMode(Qt::ElideMiddle); tw.setWordWrap(false); tw.show(); }
-
C CJha has marked this topic as solved on