[英]How can i disable or hide default cancel button in QFileDialog?
我正在嘗試將QFileDialog
用作小部件,將QFileDialog
用作小部件,我的最后一步是禁用取消按鈕。
您知道如何禁用此按鈕嗎?
PS:我使用的是 Qt 5.5.0
您應該能夠通過QDialogButtonBox
訪問各種標准按鈕,並從那里使用Cancel
按鈕執行您想要的操作。
以下示例代碼似乎按預期工作......
QFileDialog fd;
/*
* Find the QDialogButtonBox.
*/
if (auto *button_box = fd.findChild<QDialogButtonBox *>()) {
/*
* Now find the `Cancel' button...
*/
if (auto *cancel_button = button_box->button(QDialogButtonBox::Cancel)) {
/*
* ...and remove it (or disable it if you prefer).
*/
button_box->removeButton(cancel_button);
}
}
fd.show();
QFileDialog Class似乎對此沒有任何選擇。
但是,您可以使用 QTreeModel 和 QTreeView 制作自己的文件瀏覽器(這並不難)。
這里有一個關於如何做到這一點的教程。
輸入所有代碼需要一些時間(抱歉,我的打字速度很慢),但本教程應該讓您能夠靈活地完成您想做的事情。
我知道這個答案並不完全是您所要求的,但我希望這是一個不錯的選擇。
編輯:意外粘貼了 QFileDialog Class 的錯誤鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.