-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQFilePath.py
More file actions
27 lines (21 loc) · 937 Bytes
/
QFilePath.py
File metadata and controls
27 lines (21 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from PyQt6.QtWidgets import QWidget, QHBoxLayout, QLineEdit, QPushButton, QFileDialog
class QFilePath(QWidget):
def __init__(self, path=None, *args, **kwargs):
super().__init__(*args, **kwargs)
layout = QHBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
self._filePath_lbl = QLineEdit(path)
self._filePath_lbl.setFrame(False)
self._browse_btn = QPushButton('📂')
self._browse_btn.setFixedWidth(40)
self._browse_btn.setFlat(True)
self._browse_btn.clicked.connect(self._onBrowse_clicked)
layout.addWidget(self._filePath_lbl)
layout.addWidget(self._browse_btn)
self.setLayout(layout)
def text(self):
return self._filePath_lbl.text()
def _onBrowse_clicked(self):
file_path, _ = QFileDialog.getOpenFileName(self, "Select datasheet")
if file_path:
self._filePath_lbl.setText(file_path)