Hey everyone,
This is my first post here, I'm pretty new to Qt and I'd appreciate your help, thanks.
I've got a QTableView which I have stuck the example SpinBox delegate in. My problem is the when I edit a value in the table, the spinBox is has a small width due to my column heading labels being short. As a result, the values in the spinBox editor become difficult to read (seeing only one character at a time).
I attempted to use editor->setMinimumWidth(45); within the delegate constructor, which does change the size of the delegate editor when it is opened. Unfortunately the column width seems to have been determined based on the display delegate, meaning it overlaps the column to its right.
I'd appreciate it if anyone could let me know if there is an easy way to base the column's width on the size of the delegate editor not the delegate display. (not sure if my terminology is correct there)
For the set up of the table, I'm using resizeColumnsToContents() as below.
table->setModel(chanSetModel);
table->setItemDelegateForColumn(4, new SpinBoxDelegate);
table->resizeColumnsToContents();
QTableView *table = new QTableView;
table->setModel(chanSetModel);
table->setItemDelegateForColumn(4, new SpinBoxDelegate);
table->resizeColumnsToContents();
To copy to clipboard, switch view to plain text mode
... and this is my delegate constructor.
{
editor->setMinimum(0);
editor->setMaximum(63);
editor->setMinimumWidth(45);
return editor;
}
QWidget *SpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const
{
QSpinBox *editor = new QSpinBox(parent);
editor->setMinimum(0);
editor->setMaximum(63);
editor->setMinimumWidth(45);
return editor;
}
To copy to clipboard, switch view to plain text mode
Thanks in advance for your help!
- Michael
Bookmarks