QFileDialog中的后退和前进按钮没有信号

back and forward button in QFileDialog dont have signals

本文关键字:按钮 信号 QFileDialog      更新时间:2023-10-16

我正在使用QFileDialog::DontUseNativeDialog。现在我的信号有问题。这是我的示例代码:

class A : public QFileDialog
{
    A(){
       setOption(QFileDialog::DontUseNativeDialog);
       connect(this, SIGNAL(directoryEntered(const Qstring), this, SLOT(foo(const QString)));
    }
    foo(const QString path){
    QDir dir(path);
    // Code...
   }
};

现在,当我使用DontUseNativeDialog选项时,我在对话框的右上角得到了三个导航按钮,它们是:

 1. Back
 2. Forward
 3. Parent Directory

当我按下Parent Directory按钮时,就会触发信号directoryEntered(const QString)。但在"后退"answers"前进"按钮的情况下,它不起作用。有什么不同的信号我可以用吗。请帮忙。非常感谢。

QFileDialog和Qt4.8.x 也有同样的问题

解决方案是在点击按钮时手动发出信号:

class FileDialog : public QFileDialog {
public:    
    FileDialog() : QFileDialog() {
        this->fixHistoryButtons();
    }
private:
    void fixHistoryButtons() {
        QToolButton backButton = this->findChild<QToolButton *>("backButton");
        QToolButton forwardButton = this->findChild<QToolButton *>("forwardButton");
        this->connect(backButton, SIGNAL(clicked()), SLOT(backOrForwardButtonClicked()));
        this->connect(forwardButton, SIGNAL(clicked()), SLOT(backOrForwardButtonClicked()));
    }
private slots:
    void backOrForwardButtonClicked() {
        /* this->directory() should be save, since we should be called after QFileDialog has done it's thing */
        emit this->directoryChanged( this->directory().absolutePath() );
    }
};