开发者

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:

  1. Won't have a native dialog.
  2. I'll have to implement my own image preview,
  3. 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜