尝试在 QTableView 中编辑单元格时调用 QFileDialog

发布于 2024-09-27 07:47:58 字数 555 浏览 3 评论 0原文

有没有一种方法可以在不使用 QItemDelegate 的情况下做到这一点?我为此遇到了很多麻烦。例如,如果我使用委托:

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

    QWidget *createEditor(
        QWidget *父级,
        const QStyleOptionViewItem &选项,
        const QModelIndex 和索引
    ) 常量 {
    Q_UNUSED(选项);
    Q_UNUSED(索引);
    
    QFileDialog* 编辑器 = new QFileDialog(parent);
    编辑器->setFilter("*.png");
    编辑器->setDirectory(mResources);
    编辑器->setGeometry(0,0,1000,500);
    editor->exec() // <--- 大文件对话框;
    
    返回编辑器; // <--- 小文件对话框;
    };
    

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月静好 2024-10-04 07:47:58

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

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.

人│生佛魔见 2024-10-04 07:47:58

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

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

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文