Skip to content

Commit 892a7a4

Browse files
committed
Add a 'browse_icon' option to use a QToolbutton instead of a Pushbutton
1 parent f10f0ea commit 892a7a4

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

qtapputils/widgets/path.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515

1616
# ---- Third party imports
1717
from qtpy.QtCore import Signal
18+
from qtpy.QtGui import QIcon
1819
from qtpy.QtWidgets import (
1920
QCheckBox, QFrame, QLineEdit, QLabel, QFileDialog, QPushButton,
2021
QGridLayout, QWidget)
2122

23+
# ---- Local imports
24+
from qtapputils.qthelpers import create_toolbutton
2225

2326
class PathBoxWidget(QFrame):
2427
"""
@@ -28,7 +31,8 @@ class PathBoxWidget(QFrame):
2831

2932
def __init__(self, parent: QWidget = None,
3033
path_type: str = 'getExistingDirectory',
31-
filters: str = None, gettext: Callable = None):
34+
filters: str = None, gettext: Callable = None,
35+
browse_icon: QIcon = None):
3236
super().__init__(parent)
3337

3438
_ = gettext if gettext else lambda x: x
@@ -43,15 +47,25 @@ def __init__(self, parent: QWidget = None,
4347
self.filters = filters
4448
self._path_type = path_type
4549

46-
self.browse_btn = QPushButton(_("Browse..."))
47-
self.browse_btn.setDefault(False)
48-
self.browse_btn.setAutoDefault(False)
49-
self.browse_btn.clicked.connect(self.browse_path)
50-
5150
self.path_lineedit = QLineEdit()
5251
self.path_lineedit.setReadOnly(True)
53-
self.path_lineedit.setFixedHeight(
54-
self.browse_btn.sizeHint().height() - 2)
52+
if browse_icon is None:
53+
self.browse_btn = QPushButton(_("Browse..."))
54+
self.browse_btn.setDefault(False)
55+
self.browse_btn.setAutoDefault(False)
56+
self.browse_btn.clicked.connect(self.browse_path)
57+
58+
# We need to do this to align vertically the height of the
59+
# browse button with the line edit.
60+
self.path_lineedit.setFixedHeight(
61+
self.browse_btn.sizeHint().height() - 2)
62+
else:
63+
self.browse_btn = create_toolbutton(
64+
self,
65+
icon=browse_icon,
66+
text=_("Browse..."),
67+
triggered=self.browse_path,
68+
)
5569

5670
layout = QGridLayout(self)
5771
layout.setContentsMargins(0, 0, 0, 0)

0 commit comments

Comments
 (0)