0
這個問題很簡單,在標題中。如果我只想說標識符文件名稱,我如何將QRegexpValidator附加到QFileDialog?
谷歌搜索沒有幫助在這一個。我如何讓QFileDialog在其保存名稱字段上使用QValidator?
謝謝。
這個問題很簡單,在標題中。如果我只想說標識符文件名稱,我如何將QRegexpValidator附加到QFileDialog?
谷歌搜索沒有幫助在這一個。我如何讓QFileDialog在其保存名稱字段上使用QValidator?
謝謝。
以下是一些kludge,但似乎工作。
您可以使用QObject::findChildren
找到對話框的QLineEdit
子窗口小部件。假設只有一個這樣的小部件,然後您可以將驗證器應用到...
QFileDialog fd;
auto children = fd.findChildren<QLineEdit *>();
if (children.size() == 1) {
/*
* Apply a validator that forces the user to enter a name
* beginning with a lower case `a' -- a bit pointless but...
*/
QRegExpValidator validator(QRegExp("^a"));
/*
* Apply the validator.
*/
children.front()->setValidator(&validator);
fd.exec();
}
快速測試表明它似乎工作得很好。就像我說的那樣:它確實感覺像是一團糟。