PDA

View Full Version : Propper Way to a dialog as a delegate



admkrk
21st March 2017, 03:26
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()

else if(header == "Datasheet")
{
AddPDFDialog *dialog = new AddPDFDialog(parent);
connect(dialog, SIGNAL(pdfAdded(QString)),
this, SLOT(addPDF(QString)));
dialog->exec();
model->setData(index, path);

return QStyledItemDelegate::createEditor(parent, option, index);
}
and use

void CompleterDelegate::addPDF(QString path)
{
this->path = path;
}
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()?

Santosh Reddy
21st March 2017, 04:14
You could just add an function in AddPDFDialog to get the path and directly use it.


else if(header == "Datasheet")
{
AddPDFDialog *dialog = new AddPDFDialog(parent);
dialog->exec();
model->setData(index, dialog->getPath());

return QStyledItemDelegate::createEditor(parent, option, index);
}

admkrk
21st March 2017, 05:27
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.