From 9304a93735393adea0226290fdd8b1c912a26a21 Mon Sep 17 00:00:00 2001 From: WOLF Date: Thu, 10 Dec 2015 13:25:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8BasicMonitor=E4=B8=AD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E5=85=81=E8=AE=B8=E7=82=B9=E5=87=BB=E8=A1=A8?= =?UTF-8?q?=E5=A4=B4=E6=8E=92=E5=BA=8F=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E7=9A=84=E5=8F=AF=E4=BB=A5=E8=87=AA=E8=A1=8C?= =?UTF-8?q?=E5=BC=80=E5=90=AF=EF=BC=8C=E4=BD=9C=E4=B8=BA=E6=BC=94=E7=A4=BA?= =?UTF-8?q?=E6=8A=8AMarketMonitor=E7=9A=84=E8=A1=A8=E5=A4=B4=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E5=BC=80=E5=90=AF=E4=BA=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + vn.trader/uiBasicWidget.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/.gitignore b/.gitignore index 2d73e8b9..858722cd 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ Release/ # 其他文件 *.dump *.vssettings +*.klg <<<<<<< HEAD # 不想同步的 diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index be3ae136..41cb588d 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -169,6 +169,9 @@ class BasicMonitor(QtGui.QTableWidget): # 保存数据对象到单元格 self.saveData = False + # 默认不允许根据表头进行排序,需要的组件可以开启 + self.sorting = False + #---------------------------------------------------------------------- def setHeaderDict(self, headerDict): """设置表头有序字典""" @@ -214,6 +217,9 @@ class BasicMonitor(QtGui.QTableWidget): # 设为行交替颜色 self.setAlternatingRowColors(True) + + # 设置允许排序 + self.setSortingEnabled(self.sorting) #---------------------------------------------------------------------- def registerEvent(self): @@ -230,6 +236,10 @@ class BasicMonitor(QtGui.QTableWidget): #---------------------------------------------------------------------- def updateData(self, data): """将数据更新到表格中""" + # 如果允许了排序功能,则插入数据前必须关闭,否则插入新的数据会变乱 + if self.sorting: + self.setSortingEnabled(False) + # 如果设置了dataKey,则采用存量更新模式 if self.dataKey: key = data.__getattribute__(self.dataKey) @@ -279,11 +289,21 @@ class BasicMonitor(QtGui.QTableWidget): # 调整列宽 self.resizeColumns() + + # 重新打开排序 + if self.sorting: + self.setSortingEnabled(True) #---------------------------------------------------------------------- def resizeColumns(self): """调整各列的大小""" self.horizontalHeader().resizeSections(QtGui.QHeaderView.ResizeToContents) + + #---------------------------------------------------------------------- + def setSorting(self, sorting): + """设置是否允许根据表头排序""" + self.sorting = sorting + ######################################################################## @@ -322,6 +342,9 @@ class MarketMonitor(BasicMonitor): # 设置字体 self.setFont(BASIC_FONT) + # 设置允许排序 + self.setSorting(True) + # 初始化表格 self.initTable()