[英]Bring window to front -> raise(),show(),activateWindow() don’t work
[英]How i can to raise QFileDialog to the foreground if functions raise(),activeWindow() and other didn't work?
我正在使用 go-qt 綁定(therecipe)。 我遇到這樣一個問題,我無法將帶有文件對話框的 window 向前推進,我嘗試了我可以在 Inte.net 上找到的所有功能(及其組合),但沒有一個不能幫助打開對話框。
我嘗試使用這個 function:
fileDialog.SetWindowFlag(core.Qt__WindowStaysOnTopHint,true)
fileDialog.ActivateWindow()
fileDialog.SetWindowState(core.Qt__WindowActive)
fileDialog.SetWindowState(core.Qt__WindowMinimized|core.Qt__WindowActive)
fileDialog.Raise()
fileDialog.SetFocus2()
我還注意到一個特點,如果你在fileDialog.Exec()之后再次調用對話框,那么它會根據需要顯示在所有windows之上。
這種情況的代碼
var fileDialog = widgets.NewQFileDialog2(nil, "Open Directory", "", "")
if fileDialog.Exec() != int(widgets.QDialog__Accepted) {
return
}
if fileDialog.Exec() != int(widgets.QDialog__Accepted) {
return
}
我正在使用對話框的 function 代碼:
func choseFile(){
var fileDialog = widgets.NewQFileDialog2(nil, "Open Directory", "", "")
fileDialog.SetAcceptMode(widgets.QFileDialog__AcceptOpen)
fileDialog.SetFileMode(widgets.QFileDialog__ExistingFile)
fileDialog.SetWindowFlag(core.Qt__WindowStaysOnTopHint,true)
if fileDialog.Exec() != int(widgets.QDialog__Accepted) {
return
}
fmt.Println(fileDialog.SelectedFiles()[0])
}
問題可能與本機對話框有關(在我的例子中,我使用的是 ubuntu),所以我放置了標志 DontUseNativeDialog。 然后問題就解決了。
filename := widgets.QFileDialog_GetOpenFileName(ac.MainWindow,"Open Directory","","","",widgets.QFileDialog__DontUseNativeDialog)
更新:即使第一個參數為零,它也能工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.