【问题标题】:Call QFileDialog when trying to edit cell in QTableView尝试在 QTableView 中编辑单元格时调用 QFileDialog
【发布时间】:2010-10-12 19:11:23
【问题描述】:

有没有办法在不使用 QItemDelegate 的情况下做到这一点?我一直有很多麻烦。例如,如果我使用委托:

  1. 没有原生对话框。
  2. 我必须实现自己的图像预览,
  3. 由于某些原因,我无法调整窗口大小,因为 setGeometry 不起作用等等。

    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;
    };
    

【问题讨论】:

    标签: editor qtableview qitemdelegate qfiledialog


    【解决方案1】:

    在实践中,改变小部件几何形状的所有内容都会转到 updateEditorGeometry 函数。覆盖它以避免尝试将原始对话框放在表格的单元格中。

    【讨论】:

      【解决方案2】:

      好的,所以 editor->setGeometry 方法必须进入 QItemDelegate 的重写方法 setEditorData。

      有人知道使用 setItemDelegate 绘制 QFileDialog 中图像的缩略图预览的示例代码吗?

      【讨论】:

        猜你喜欢
        • 2012-01-18
        • 1970-01-01
        • 1970-01-01
        • 2010-11-22
        • 1970-01-01
        • 2021-10-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多