Results 1 to 3 of 3

Thread: Propper Way to a dialog as a delegate

  1. #1
    Join Date
    Apr 2014
    Posts
    59
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Propper Way to a dialog as a delegate

    I have a column in my table view that holds links to either an online PDF, or a local one. The default editor is fine for just adding web links, but more troublesome for adding a file path. I made a dialog where the user can paste a web link, or open a QFileDialog to get the path. I currently have, in createEditor()
    Qt Code:
    1. else if(header == "Datasheet")
    2. {
    3. AddPDFDialog *dialog = new AddPDFDialog(parent);
    4. connect(dialog, SIGNAL(pdfAdded(QString)),
    5. this, SLOT(addPDF(QString)));
    6. dialog->exec();
    7. model->setData(index, path);
    8.  
    9. return QStyledItemDelegate::createEditor(parent, option, index);
    10. }
    To copy to clipboard, switch view to plain text mode 
    and use
    Qt Code:
    1. void CompleterDelegate::addPDF(QString path)
    2. {
    3. this->path = path;
    4. }
    To copy to clipboard, switch view to plain text mode 
    to catch the slot. this->path is a public QString.

    It works fine, so far, but it seems like sort of a hack creating the variable. Is there a way to access the slot, directly, inside of createEditor()?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Propper Way to a dialog as a delegate

    You could just add an function in AddPDFDialog to get the path and directly use it.
    Qt Code:
    1. else if(header == "Datasheet")
    2. {
    3. AddPDFDialog *dialog = new AddPDFDialog(parent);
    4. dialog->exec();
    5. model->setData(index, dialog->getPath());
    6.  
    7. return QStyledItemDelegate::createEditor(parent, option, index);
    8. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following user says thank you to Santosh Reddy for this useful post:

    admkrk (21st March 2017)

  4. #3
    Join Date
    Apr 2014
    Posts
    59
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Propper Way to a dialog as a delegate

    If I understand right, that means drop the signal/slot altogether. I will give it a try tomorrow.

    Actually, as I was walking away, it seemed like too easy a fix let go.

    Once again, you taught me something new.
    Last edited by admkrk; 21st March 2017 at 05:46.

Similar Threads

  1. Propper dimension for a taskbar icon.
    By robgeek in forum Newbie
    Replies: 1
    Last Post: 11th February 2016, 20:38
  2. Tableview dialog as delegate
    By drmacro in forum Qt Programming
    Replies: 5
    Last Post: 28th October 2015, 07:45
  3. How to do QChartView delegate like QTableView item delegate
    By malleeswarareddy.s in forum Qt Programming
    Replies: 0
    Last Post: 16th September 2015, 11:37
  4. Replies: 1
    Last Post: 2nd December 2010, 15:00
  5. Replies: 0
    Last Post: 11th February 2010, 09:33

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.