简体   繁体   中英

how to hide sidebar in QFileDialog?

I need to hide/disable the sidebar (QSidebar) in the QFileDialog.

I've solved this problem using magic-woodoo with d-pointer and editing Qt source code (just like this ).

Is there any more simple way to do it?

Thanks

Old-Question,

I have a 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

It is a hacky solution but since I was searching for the same question, I thought I would share the code that I eventually settled for.

ps-- I didn't have the chance to compile the above code: sorry about the potential bugs and typos. Hopefully you can use the idea here.

QFileDialog uses the native dialog if possible. So if you want to use Qt in a cross platform way the short answer is no.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM