免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4016 | 回复: 1

pyqt 界面QTreeView 鼠标应用 [复制链接]

论坛徽章:
0
发表于 2013-12-30 16:56 |显示全部楼层

我想加入双击一条数据弹出一个窗口,在窗口中显示数据的索引

*************************************************************

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This is only needed for Python v2 but is harmless for Python v3.
import sip
sip.setapi('QVariant', 2)

from PyQt4 import QtCore, QtGui
import codebase

SUBJECT, SENDER, DATE, KAIJIANGLI = range(4)


              
# Work around the fact that QSortFilterProxyModel always filters datetime
# values in QtCore.Qt.ISODate formeat, but the tree views display using
# QtCore.Qt.DefaultLocaleShortDate format.
class SortFilterProxyModel(QtGui.QSortFilterProxyModel):
    def filterAcceptsRow(self, sourceRow, sourceParent):
        # Do we filter for the date column?
        if self.filterKeyColumn() == DATE:
            # Fetch datetime value.
            index = self.sourceModel().index(sourceRow, DATE, sourceParent)
            data = self.sourceModel().data(index)

            # Return, if regExp match in displayed format.
            return (self.filterRegExp().indexIn(data.toString(QtCore.Qt.DefaultLocaleShortDate)) >= 0)

        # Not our business.
        return super(SortFilterProxyModel, self).filterAcceptsRow(sourceRow, sourceParent)


class Window(QtGui.QWidget):
    def __init__(self):
        super(Window, self).__init__()

        self.proxyModel = SortFilterProxyModel()
        self.proxyModel.setDynamicSortFilter(True)

        self.proxyGroupBox = QtGui.QGroupBox(u" 两码定位 ")


        self.proxyView = QtGui.QTreeView()
        self.proxyView.setRootIsDecorated(False)
        self.proxyView.setAlternatingRowColors(True)
        self.proxyView.setModel(self.proxyModel)
        self.proxyView.setSortingEnabled(True)

      
        proxyLayout = QtGui.QGridLayout()
        proxyLayout.addWidget(self.proxyView, 0, 0, 1, 3)
      
        
      
        self.proxyGroupBox.setLayout(proxyLayout)

        mainLayout = QtGui.QVBoxLayout()
      
        mainLayout.addWidget(self.proxyGroupBox)
        self.setLayout(mainLayout)

        self.setWindowTitle(u"两码定位 - 0369")
        self.resize(500, 450)

        self.proxyView.sortByColumn(SENDER, QtCore.Qt.AscendingOrder)
        
  

    def setSourceModel(self, model):
        self.proxyModel.setSourceModel(model)
        

    def filterRegExpChanged(self):
        syntax = QtCore.QRegExp.PatternSyntax(syntax_nr)
        if self.filterCaseSensitivityCheckBox.isChecked():
            caseSensitivity = QtCore.Qt.CaseSensitive
        else:
            caseSensitivity = QtCore.Qt.CaseInsensitive

        

def addMail(model, subject, sender, date, kaijiangli):
    model.insertRow(0)
    model.setData(model.index(0, SUBJECT), subject)
    model.setData(model.index(0, SENDER), sender)
    model.setData(model.index(0, DATE), date)
    model.setData(model.index(0, KAIJIANGLI), kaijiangli)


def createMailModel(parent):
    model = QtGui.QStandardItemModel(0, 4, parent)

    model.setHeaderData(SUBJECT, QtCore.Qt.Horizontal, "Subject")
    model.setHeaderData(SENDER, QtCore.Qt.Horizontal, u"title1")
    model.setHeaderData(DATE, QtCore.Qt.Horizontal, u"title2")
    model.setHeaderData(KAIJIANGLI, QtCore.Qt.Horizontal, u"title3")

   
    addMail(model,"1","2","3","4")
    addMail(model,"1","2","3","4")
    addMail(model,"1","2","3","4")
    addMail(model,"1","2","3","4")
    addMail(model,"1","2","3","4")

    return model


if __name__ == '__main__':

    import sys

    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.setSourceModel(createMailModel(window))
    window.show()
    sys.exit(app.exec_())

论坛徽章:
0
发表于 2013-12-31 09:59 |显示全部楼层
没人看呀。顶一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

SACC2019中国系统架构师大会

【数字转型 架构演进】SACC2019中国系统架构师大会
2019年10月31日~11月2日第11届中国系统架构师大会(SACC2019)将在北京隆重召开。四大主线并行的演讲模式,1个主会场、20个技术专场、超千人参与的会议规模,100+来自互联网、金融、制造业、电商等领域的嘉宾阵容,将为广大参会者提供一场最具价值的技术交流盛会。




----------------------------------------

大会官网>>
  

北京盛拓优讯信息技术有限公司. 版权所有 16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122
中国互联网协会会员  联系我们:huangweiwei@it168.com
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP