0

我需要在 QFileDialog 中隐藏/禁用侧边栏(Qsidebar)。

我已经使用带有 d-pointer 的 magic-woodoo 和编辑 Qt 源代码(就像这样)解决了这个问题。

有没有更简单的方法来做到这一点?

谢谢

4

2 回答 2

0

老问题,

我有一个 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——我没有机会编译上面的代码:对于潜在的错误和错别字,我很抱歉。希望你可以在这里使用这个想法。

于 2020-08-19T19:27:46.873 回答
-1

如果可能,QFileDialog 使用本机对话框。因此,如果您想以跨平台方式使用 Qt,简短的回答是否定的。

于 2013-03-05T11:24:32.010 回答