2017-04-14 29 views

回答

1

以下是一些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(); 
} 

快速測試表明它似乎工作得很好。就像我說的那樣:它確實感覺像是一團糟。

相關問題