Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableWidget elide middle not working as expected
Forum Update on Monday, May 27th 2025

QTableWidget elide middle not working as expected

Scheduled Pinned Locked Moved Solved General and Desktop
qtablewidgetelide mode
2 Posts 2 Posters 328 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CJha
    wrote on 26 Jul 2024, 06:50 last edited by
    #1

    Hi, I am using Qt 6.5. I have a QTableWidget and am trying to set the elide mode to Qt::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 use QTableWidget::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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 26 Jul 2024, 11:02 last edited by Christian Ehrlicher
      #2

      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();
      }
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • C CJha has marked this topic as solved on 29 Jul 2024, 06:44

      2/2

      26 Jul 2024, 11:02

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved