I want to doubleclick on a header in a QTableWidget and open an editor to change the text. Having trouble with the MVC paradigm. I created my own QHeaderView, and overrode mousedoubleclickevent(). Now I don't know what to do
{
Q_OBJECT
public:
setItemDelegate(&delegate);
}
protected slots:
virtual void mouseDoubleClickEvent
( QMouseEvent *me
) { QModelIndex index
= model
()->index
(logicalIndexAt
(me
->x
(), me
->y
()),
0);
//openPersistentEditor(index);
//QItemDelegate *delegate = new QItemDelegate(this);
//delegate->createEditor(lineEdit, QStyleOptionViewItem() , QModelIndex());
delegate.setEditorData();
};
private:
};
MyTableWidget::MyTableWidget(int rows, int columns)
{
RowHeaderView *rowHeaderView = new RowHeaderView(this);
setVerticalHeader(rowHeaderView);
...
class RowHeaderView : public QHeaderView
{
Q_OBJECT
public:
RowHeaderView(QWidget* parent=0) : QHeaderView(Qt::Vertical, parent) {
setItemDelegate(&delegate);
}
protected slots:
virtual void mouseDoubleClickEvent( QMouseEvent *me ) {
QModelIndex index = model()->index(logicalIndexAt(me->x(), me->y()), 0);
//openPersistentEditor(index);
QLineEdit *lineEdit = new QLineEdit(this);
//QItemDelegate *delegate = new QItemDelegate(this);
//delegate->createEditor(lineEdit, QStyleOptionViewItem() , QModelIndex());
delegate.setEditorData();
};
private:
QItemDelegate delegate;
};
MyTableWidget::MyTableWidget(int rows, int columns)
: QTableWidget(rows, columns)
{
RowHeaderView *rowHeaderView = new RowHeaderView(this);
setVerticalHeader(rowHeaderView);
...
To copy to clipboard, switch view to plain text mode
Bookmarks