Call QFileDialog when trying to edit cell in QTableView
I开发者_运维技巧s there a way of doing this without using a QItemDelegate? I've been having a lot of trouble with it. For example, if I use a Delegate:
- Won't have a native dialog.
- I'll have to implement my own image preview,
For some reason I can't resize the window cause setGeometry doesn't work, etc etc.
QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const { Q_UNUSED(option); Q_UNUSED(index); QFileDialog* editor = new QFileDialog(parent); editor->setFilter("*.png"); editor->setDirectory(mResources); editor->setGeometry(0,0,1000,500); editor->exec() // <--- big file dialog; return editor; // <--- tiny file dialog; };
In practice, everything that changes the geometry of your widget goes to updateEditorGeometry function. Override it to avoid trying the original one to put your dialog within the cell of the table.
OK so the editor->setGeometry method has to go in the overridden method setEditorData of the QItemDelegate.
Does anyone know of an example code where the setItemDelegate is used to paint the thumbnail preview of the images in the QFileDialog?
精彩评论