Reputation: 141
What's the best approach to mimic the Windows Explorer navigation bar in PyQt?. Perhaps a list of QComboBox
es 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.
Thanks in advance
Upvotes: 2
Views: 675
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.
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
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:
QWidget
-derived class with your implementation, which would have:
QHBoxLayout
QComboBox
esQFileSystemModel
from which to populate the combo boxes.You could use a single QLabel
s 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 QToolButton
s backed by a tree of QAction
/QMenu
s. 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