qteditbox

Qt tablewidget editbox


I created a tablewidget like this:

Tablewidget

I want to edit cell(0) value, (double click), but the edit box was too big and it covers cell(1):

Tablewidget2

How do I avoid the edit box covering the cell after it?


Solution

  • You should make your own children QStyledItemDelegate and redefine QStyledItemDelegate::createEditor method.

    Something like that:

    QWidget * MyStyledItemDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const 
    {
        QWidget * editor = QStyledItemDelegate::createEditor(parent, option, index);
        editor->setWidth( 20 ); // Handle editor here.
        return editor;
    }