PyQt
This commit is contained in:
parent
7930a383a5
commit
6c687af34f
6 changed files with 9862 additions and 9849 deletions
|
@ -48,10 +48,10 @@ class SortFilterProxyModel(QSortFilterProxyModel):
|
|||
self.setFilterRegExp(QRegExp(item_code[:-2] + "\d\d"))
|
||||
|
||||
|
||||
class Widget(QWidget):
|
||||
class CityLinkageWindow(QWidget):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Widget, self).__init__(*args, **kwargs)
|
||||
super(CityLinkageWindow, self).__init__(*args, **kwargs)
|
||||
layout = QHBoxLayout(self)
|
||||
self.province_box = QComboBox(self, minimumWidth=200) # 市级以上
|
||||
self.city_box = QComboBox(self, minimumWidth=200) # 市
|
||||
|
@ -88,7 +88,7 @@ class Widget(QWidget):
|
|||
|
||||
def initData(self):
|
||||
# 初始化数据
|
||||
datas = open("data.json", "rb").read()
|
||||
datas = open("Data/data.json", "rb").read()
|
||||
encoding = chardet.detect(datas) or {}
|
||||
datas = datas.decode(encoding.get("encoding", "utf-8"))
|
||||
datas = json.loads(datas)
|
||||
|
@ -108,6 +108,6 @@ class Widget(QWidget):
|
|||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
w = Widget()
|
||||
w = CityLinkageWindow()
|
||||
w.show()
|
||||
sys.exit(app.exec_())
|
|
@ -0,0 +1,12 @@
|
|||
# QComboBox
|
||||
|
||||
## 1、Data Linkage
|
||||
[View](CityLinkage.py) | [Run](CityLinkage.py)
|
||||
|
||||
Three level linkage, data file is data.json
|
||||
|
||||
1. use `QComboBox`,`setModel` and `QSortFilterProxyModel` to filter
|
||||
2. the filter role is `Qt::ToolTipRole`
|
||||
3. can use `QColumnView` maybe like this example
|
||||
|
||||
![CityLinkage](ScreenShot/CityLinkage.gif)
|
|
@ -0,0 +1,12 @@
|
|||
# QComboBox
|
||||
|
||||
## 1、下拉数据关联
|
||||
[查看](CityLinkage.py) | [运行](CityLinkage.py)
|
||||
|
||||
一个省市区关联的三级联动,数据源在data.json中
|
||||
|
||||
1. 主要用了`QComboBox`的`setModel`设置一个`QSortFilterProxyModel`过滤模型
|
||||
2. 并根据唯一编码过滤,为了不影响内容显示,唯一编码的角色为`ToolTipRole`
|
||||
3. 用`QColumnView`可以实现类似效果
|
||||
|
||||
![CityLinkage](ScreenShot/CityLinkage.gif)
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
|
@ -1,11 +0,0 @@
|
|||
# 下拉框
|
||||
|
||||
## [1、QComboBox下拉数据关联](下拉选择联动)
|
||||
|
||||
这里简单的做了一个省市区关联的三级联动,数据源在data.json中
|
||||
|
||||
1. 主要用了`QComboBox`的`setModel`设置一个`QSortFilterProxyModel`过滤模型
|
||||
2. 并根据唯一编码过滤,为了不影响内容显示,唯一编码的角色为`ToolTipRole`
|
||||
3. 匆忙中写出来,可能有些不完善,或者该方式效率不是很高(后来发现可以用`QColumnView`实现)
|
||||
|
||||
![截图](下拉选择联动/ScreenShot/下拉选择联动.gif)
|
Loading…
Reference in a new issue