Skip to main content
 首页 » 编程设计

python之如何在 pyQt 中调整 QFileDialog 的大小

2025年05月04日21mengfanrong

这是我关于显示 QFileDialog 的部分代码。

expand='Image Files(*.mp3 *.wav)' 
tips=u'choose the music file' 
path = QtGui.QFileDialog.getOpenFileName(self, tips, QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.MusicLocation), expand) 

然后会出现选择文件的窗口。
但是它的尺寸对我来说太大了。
我要设置的尺寸是320*240。
但是我不知道该怎么做。
希望有人能解决这个问题。

请您参考如下方法:

我认为唯一的选择是不使用便利函数 getOpenFileName。 您将需要自己创建 Dialog 并连接其信号。

像这样:

def fileSelected(self, filename): 
    print(filename) 
 
def showDialog(self): 
    filedialog = QtGui.QFileDialog() 
    filedialog.fileSelected.connect(self.fileSelected) 
    filedialog.setFixedSize(320,240) 
    filedialog.show()