Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-74327

Spin box in table cell too wide

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.12.3, 5.14.0 Alpha
    • 5.11, 5.12.1
    • Widgets: Itemviews
    • None
    • KDE Neon 18.04
    • All
    • b8d5e0b4ce2f1daef35dad38f5048040ae915412 (qt/qtbase/5.12)

    Description

      Try the following code:

       

      class TestModel final : public QAbstractTableModel
      {
       public:
       virtual int rowCount(const QModelIndex& pParent = QModelIndex()) const override { return 10; }
      virtual int columnCount(const QModelIndex& pParent = QModelIndex()) const override { return 1; }
      virtual QVariant data(const QModelIndex& pIndex, int pRole = Qt::DisplayRole) const override
       {
       if (pRole == Qt::DisplayRole || pRole == Qt::EditRole)
       return pIndex.row();
      return QVariant();
       }
      virtual QVariant headerData(int pSection, Qt::Orientation pOrientation, int pRole = Qt::DisplayRole) const override
       {
       if (pOrientation == Qt::Horizontal && pRole == Qt::DisplayRole)
       return "Heading";
       return QVariant();
       }
      virtual Qt::ItemFlags flags(const QModelIndex& pIndex) const override
       {
       return QAbstractTableModel::flags(pIndex) | Qt::ItemIsEditable;
       }
      virtual bool setData(const QModelIndex& pIndex, const QVariant& pValue, int pRole = Qt::EditRole) override
       {
       qDebug() << pRole << pIndex << pValue;
       return true;
       }
      };
      

       

      TestModel m;
      QTableView w;
      w.setModel(&m);
      w.setColumnWidth(0, 50);
      w.show();

      Now edit one of the cells by double clicking it. You will see that a spin box opens.

      The small numbers easily fit into the given column width. Still the spin box has about twice the width of the column. This is not necessary since the spin box easily could have the columns width, avoiding an ugly, broken visual appearance (see the attached image; please not that the appearance gets much nastier with additional columns to the right).

      It seems the spin box always opens with at least the default column width and does not take smaller column widths into account.

      Attachments

        1. main.cpp
          2 kB
        2. snap.png
          snap.png
          11 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            chehrlic Christian Ehrlicher
            silicomancer Bernhard Lindner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes