2021-04-13 14:40:32 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Created on 2020/9/14
|
|
|
|
@author: Irony
|
2021-07-13 14:52:26 +08:00
|
|
|
@site: https://pyqt.site , https://github.com/PyQt5
|
2021-04-13 14:40:32 +08:00
|
|
|
@email: 892768447@qq.com
|
|
|
|
@file: ColumnView
|
|
|
|
@description:
|
|
|
|
"""
|
|
|
|
|
2021-07-13 14:52:26 +08:00
|
|
|
try:
|
|
|
|
from PyQt5.QtWidgets import QApplication, QComboBox, QFileSystemModel, QHBoxLayout, QSpacerItem, \
|
|
|
|
QSizePolicy
|
|
|
|
except ImportError:
|
|
|
|
from PyQt5.QtWidgets import QApplication, QComboBox, QFileSystemModel, QHBoxLayout, QSpacerItem, \
|
|
|
|
QSizePolicy
|
2021-04-13 14:40:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
class PathComboBox(QComboBox):
|
|
|
|
|
|
|
|
def __init__(self, *args, is_item=False, **kwargs):
|
|
|
|
super(PathComboBox, self).__init__(*args, **kwargs)
|
|
|
|
self.is_item = is_item
|
|
|
|
if not self.is_item:
|
|
|
|
self.setEditable(True)
|
|
|
|
layout = QHBoxLayout(self)
|
|
|
|
layout.setSpacing(0)
|
|
|
|
layout.setContentsMargins(0, 0, 0, 23)
|
|
|
|
layout.addItem(QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum))
|
|
|
|
else:
|
|
|
|
self.f_model = QFileSystemModel(self)
|
|
|
|
self.f_model.setRootPath('')
|
|
|
|
self.setModel(self.f_model)
|
|
|
|
|
|
|
|
def addWidget(self, widget):
|
2021-07-13 14:52:26 +08:00
|
|
|
self.layout().insertWidget(self.layout().count() - 1, widget)
|
2021-04-13 14:40:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
w = PathComboBox()
|
|
|
|
w.show()
|
|
|
|
w.addWidget(PathComboBox(w, is_item=True))
|
|
|
|
sys.exit(app.exec_())
|