Results 1 to 3 of 3

Thread: Call QFileDialog when trying to edit cell of QTableView, put file name after return.

  1. #1
    Join Date
    Jun 2010
    Posts
    36
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Call QFileDialog when trying to edit cell of QTableView, put file name after return.

    Hi, In my QTableView one of my columns refers to a file name, so when editing a cell of this column I would like to call a QFileDialog to make the user choose the file. And I know this can be done with a QItemDelegate.

    So, this is my createEditor attempt:
    Qt Code:
    1. QWidget *createEditor(
    2. QWidget *parent,
    3. const QStyleOptionViewItem &option,
    4. const QModelIndex &index
    5. ) const {
    6. Q_UNUSED(option);
    7. Q_UNUSED(index);
    8.  
    9. QFileDialog* editor = new QFileDialog(parent);
    10. editor->setFilter("*.png");
    11. editor->setDirectory(mResources);
    12.  
    13. return editor;
    14. };
    To copy to clipboard, switch view to plain text mode 

    And actually this does work. But I still wish I could use getOpenFileName to get the native dialog which looks cooler and also shows a preview of the images.

    So is there a better way of doing this that I can use getOpenFileName method, maybe attaching some signals or slots?

    Thanks for any help.
    Last edited by toglia3d; 12th October 2010 at 19:25.

  2. #2
    Join Date
    Jun 2010
    Posts
    36
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call QFileDialog when trying to edit cell of QTableView, put file name after retu

    I can't even resize the dialog window. Something weird is happening when I return the editor that's changing the geometry of the QFileDialog.

    Qt Code:
    1. QWidget *createEditor(
    2. QWidget *parent,
    3. const QStyleOptionViewItem &option,
    4. const QModelIndex &index
    5. ) const {
    6. Q_UNUSED(option);
    7. Q_UNUSED(index);
    8.  
    9. QFileDialog* editor = new QFileDialog(parent);
    10. editor->setFilter("*.png");
    11. editor->setDirectory(mResources);
    12. editor->setGeometry(0,0,1000,500);
    13. editor->exec() // <--- big file dialog;
    14.  
    15. return editor; // <--- tiny file dialog;
    16. };
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2010
    Posts
    36
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Call QFileDialog when trying to edit cell of QTableView, put file name after retu

    OK so the editor->setGeometry method has to go in the override 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?

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  2. Replies: 11
    Last Post: 3rd October 2010, 11:22
  3. Replies: 1
    Last Post: 19th March 2010, 13:59
  4. Replies: 8
    Last Post: 23rd October 2009, 15:33
  5. Replies: 7
    Last Post: 3rd July 2008, 08:02

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.