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: smaller text when it doesn't fit it a column
Forum Updated to NodeBB v4.3 + New Features

QTableWidget: smaller text when it doesn't fit it a column

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.1k 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
    cidadao
    wrote on last edited by cidadao
    #1

    Hey guys,

    When text doesn't fit in a column it automatically gets smaller and three dots are appended at the end. Like this:
    alt text

    Now I would like to understand why the text actually gets smaller and how can I control how small (or not) it gets.
    Also, as you can see on the image, since it gets smaller it ends up not using the whole width of that column which makes no sense at all.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      I see no reason (looking in QCommonStylePrivate::viewItemDrawText) why it should get smaller, it might be a bug in your platform's style.

      EDIT

      the font getting smaller is a reported bug. tableWidget->setFont(QApplication::font()); seams to be enough to fix it

      To get rid of eliding altogether just subclass QStyledItemDelegate and reimplement paint like:

      #include <QStyledItemDelegate>
      class NoElideDelegate : public QStyledItemDelegate{
      Q_OBJECT
      Q_DISABLE_COPY(NoElideDelegate)
      public:
      explicit NoElideDelegate(Qobject* parent = Q_NULLPTR):QStyledItemDelegate(parent){}
      virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE
      {
          Q_ASSERT(index.isValid());
      
          QStyleOptionViewItem opt = option;
          initStyleOption(&opt, index);
      
          //This is the change that prevents elision
          opt.textElideMode = Qt::ElideNone;
      
          const QWidget *widget = option.widget;
          QStyle *style = widget ? widget->style() : QApplication::style();
          style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
      }
      };
      

      and then use it like
      tableWidget->setItemDelegate(new NoElideDelegate(tableWidget));

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4
      • C Offline
        C Offline
        cidadao
        wrote on last edited by
        #3

        Oh great! That indeed solves the problem. Thanks @VRonin !

        1 Reply Last reply
        0

        • Login

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