HOW TO: Add a button to QFileDialog ? [solved]



  • I try to add a button to QFileDialog... i follow many (old) discution who talk about that and follow each of them... without any success.
    Here is my code (i don't know with the new forum how to add code... nothing is indicate for do it well):

    #include "addfilestobinder.h"
    #include <QDialogButtonBox>
    #include <QPushButton>
    #include <QBoxLayout>
    #include <QEvent>
    #include <QMessageBox>

    addFilesToBinder::addFilesToBinder(QWidget *parent,
    QString startdir) :
    QFileDialog(parent, tr("Load Correct Format"), startdir),
    myOpenButton(0) {
    // this->setOption(QFileDialog::DontUseNativeDialog, false);
    if (acceptMode() == QFileDialog::AcceptOpen) {
    QDialogButtonBox *button_box = findChild<QDialogButtonBox *>("buttonBox");
    QPushButton *add = new QPushButton(this);
    add->setText("ADD");
    QGridLayout layout = (QGridLayout)this->layout();
    layout->addWidget(add, 0, 0);
    if (button_box) {
    myOpenButton = (QPushButton *)button_box->button(QDialogButtonBox::Open);
    QString buttonText = myOpenButton->text(); } }
    connect(this, SIGNAL(currentChanged(const QString&)), this, SLOT(fileSelectionChanged(const QString&)));
    myOpenButton->installEventFilter(this);
    }

    addFilesToBinder::~addFilesToBinder() {

    }

    bool addFilesToBinder::eventFilter(QObject* obj, QEvent* event) {
    // QEvent::Type type = event->type();
    if (obj == myOpenButton) {
    if(event->type() == QEvent::EnabledChange &&
    myOpenButton->isEnabled() &&
    !validSelection()) {
    myOpenButton->setEnabled(false);
    return true; }
    else
    return false; }
    // pass unfiltered events on to the parent class
    return QFileDialog::eventFilter(obj, event);
    }

    bool addFilesToBinder::validSelection() {
    QFileInfo fileInfo(currentFile);
    if (fileInfo.exists()) {
    return true; }
    return false;
    }

    void addFilesToBinder::fileSelectionChanged(const QString &file) {
    currentFile = file;
    }



  • @jerome_isAviable My problem was that i call it by a member function (QList<QUrl> urls_to_add = dialogDirsOfiles->getOpenFileUrls(.....

    but this not works like that, i had to call by "->show()".
    and with my button, i think i have to send a signaland catch it on the caller class.
    So i consider this as "solved"


  • Lifetime Qt Champion

    @jerome_isAviable said:

    getOpenFileUrls

    is not a member function per se, it's a static function, that's why you didn't got what you wanted.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.