Ramiro Tell
Ramiro Tell

Reputation: 141

Windows Explorer Navigation Bar in PyQt

What's the best approach to mimic the Windows Explorer navigation bar in PyQt?. Perhaps a list of QComboBoxes as part of a parent class that concatenates the current item of each combo box to resolve the final path?

Is it possible to get a similar look by using stylesheets?

This is the object I need to mimic. I just want a theoretical approach about the best way to mimic it.

enter image description here

Thanks in advance

Upvotes: 2

Views: 675

Answers (2)

Winand
Winand

Reputation: 2433

I was looking for such a widget too without any luck. So I've tried to implement this by myself. It's not finished yet and needs some more work, but here's the first result: breadcrumbsaddressbar. screenshot It's based on QToolButton widgets with menu. Parts of address which don't fit are hidden like in Windows Explorer. Also the widget has auto-completion feature.

Update: there's also a C++ widget QtAddressBar which I have't tried.

Upvotes: 0

jonspaceharper
jonspaceharper

Reputation: 4367

This is technically known as a breadcrumb widget.

There are multiple approaches to this. The closest emulation to Windows Explorer's behavior--leaving out the normally hidden line editor--involves a chain of widgets like so:

  • A top level parent QWidget-derived class with your implementation, which would have:
    • A QHBoxLayout
      • An arbitrary number of QComboBoxes
    • A QFileSystemModel from which to populate the combo boxes.

Alternatives

You could use a single QLabels with a series of hyperlinks divided by path separators if you don't care about drop-down behavior. Qt Creator does this.

If your data source is static and not as gigantic as the filesystem, you could use QToolButtons backed by a tree of QAction/QMenus. This is possibly a masochistic approach, given that you have to populate all of the actions and menus. Since that's what they are there for, though, it might be handy as part of a context-sensitive menubar or tab bar.

Upvotes: 1

Related Questions