【发布时间】:2013-03-05 11:00:18
【问题描述】:
我需要在 QFileDialog 中隐藏/禁用侧边栏 (QSidebar)。
我已经使用带有 d-pointer 的 magic-woodoo 解决了这个问题,并编辑了 Qt 源代码(就像 this)。
还有更简单的方法吗?
谢谢
【问题讨论】:
标签: c++ qt qfiledialog
我需要在 QFileDialog 中隐藏/禁用侧边栏 (QSidebar)。
我已经使用带有 d-pointer 的 magic-woodoo 解决了这个问题,并编辑了 Qt 源代码(就像 this)。
还有更简单的方法吗?
谢谢
【问题讨论】:
标签: c++ qt qfiledialog
老问题,
我有一个 python hack:
fd = QtGui.QFileDialog()
...
# search for the sidebar and hide it when found
sidebar = None
views = fd.findChildren(QListView)
for obj in views:
if obj.objectName() == "sidebar":
sidebar = obj
break
if sidebar is not None:
sidebar.hide() # hidden away!
# ...now search for the splitter handle and hide it too
splitter = None
splitters = fd.findChildren(QSplitter)
for obj in splitters:
if obj.objectName() == "splitter":
obj.setHandleWidth(0) # hidden -- sort of
break
这是一个 hacky 解决方案,但由于我正在寻找同一个问题,我想我会分享我最终解决的代码。
ps-- 我没有机会编译上面的代码:对于潜在的错误和错别字,我很抱歉。希望你可以在这里使用这个想法。
【讨论】:
如果可能,QFileDialog 使用本机对话框。因此,如果您想以跨平台方式使用 Qt,那么简短的回答是否定的。
【讨论】: