当前位置: 首页>>代码示例>>Python>>正文


Python QTableView.selectedIndexes方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QTableView.selectedIndexes方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.selectedIndexes方法的具体用法?Python QTableView.selectedIndexes怎么用?Python QTableView.selectedIndexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QTableView的用法示例。


在下文中一共展示了QTableView.selectedIndexes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MyWin

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import selectedIndexes [as 别名]
class MyWin(QWidget):
    def __init__(self, mydb):
        super(MyWin, self).__init__()
        main_lt = QVBoxLayout()
        self.view = QTableView()
        main_lt.addWidget(self.view)
        self.view.setWindowTitle("Table Model (View 1)")
        self.view.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.mydb = mydb

        button = QPushButton("Join")
        button.clicked.connect(self.merge)
        main_lt.addWidget(button)

        button = QPushButton("Exit")
        button.clicked.connect(lambda: exit())
        main_lt.addWidget(button)

        self.setLayout(main_lt)
        self.setWindowTitle('QT1')

    def set_model(self):
        self.view.setModel(self.mydb.get_model())

    def merge(self):
        ind_list = self.view.selectedIndexes()
        out = list(self.view.model().data(i) for i in ind_list)
        out = [out[i] for i in range(len(out)) if i % 2 == 0]
        if len(out) < 2:
            return
        self.mydb.merge(out)
        mb = QMessageBox()
        mb.setText('Merged %s' % str(out))
        mb.exec_()
        self.set_model()
开发者ID:greyfenrir,项目名称:qt.ex,代码行数:37,代码来源:master.py

示例2: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import selectedIndexes [as 别名]

#.........这里部分代码省略.........
        self.model2.setHeaderData(1, Qt.Horizontal, "개수")


    def setupViews(self):
        splitter = QSplitter()
        self.table = QTableView()
        self.pieChart = PieView()


        splitter.addWidget(self.pieChart)
        splitter.addWidget(self.table)
        splitter.setStretchFactor(0, 0)
        splitter.setStretchFactor(1, 0)

        self.table.setModel(self.model)
        self.pieChart.setModel(self.model2)

        self.selectionModel = QItemSelectionModel(self.model2)
        self.table.setSelectionModel(self.selectionModel)

        #self.pieChart.setSelectionModel(self.selectionModel)

        #table.setColumnWidth(0,100)
        self.setCentralWidget(splitter)
        self.table.doubleClicked.connect(self.ClickAction_table)

    def readDB(self):

        con = sqlite3.connect("mystudy.db")
        cur = con.cursor()
        cur.execute("select subject, readcheck from study;")
        self.model.removeRows(0, self.model.rowCount(QModelIndex()),
                        QModelIndex())
        self.model2.removeRows(0, self.model2.rowCount(QModelIndex()),
                        QModelIndex())
        row = 0
        for line in cur:
            if line[1] ==1:
                result = "○"
            else:
                result = "X"
            self.model.insertRows(row, 1, QModelIndex())
            self.model.setData(self.model.index(row, 0, QModelIndex()), line[0])
            self.model.setData(self.model.index(row, 1, QModelIndex()),result)
            self.model.setData(self.model.index(row, 1, QModelIndex()), QVariant(Qt.AlignCenter),Qt.TextAlignmentRole)
            row += 1
        cur.execute("select count() from study ;")
        for line in cur:
            self.studyTotal =line[0]
        cur.execute("select count() from study where readcheck=1;")
        for line in cur:
            self.studyRead =line[0]
        #print("총 개수 " ,self.studyTotal ," 학습한개수", self.studyRead )
        con.close()
        row=0
        self.model2.insertRows(row, 1, QModelIndex())
        self.model2.setData(self.model2.index(row, 0, QModelIndex()),"학습")
        self.model2.setData(self.model2.index(row, 1, QModelIndex()), float(self.studyRead))
        self.model2.setData(self.model2.index(row, 0, QModelIndex()), QColor("#99e600"), Qt.DecorationRole)
        row=1
        self.model2.insertRows(row, 1, QModelIndex())
        self.model2.setData(self.model2.index(row, 0, QModelIndex()),"미학습")
        self.model2.setData(self.model2.index(row, 1, QModelIndex()), float(self.studyTotal-self.studyRead))
        self.model2.setData(self.model2.index(row, 0, QModelIndex()), QColor("#8080b3"), Qt.DecorationRole)


        self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table.setSelectionMode(QAbstractItemView.SingleSelection)
        self.table.setDragEnabled(False)
        self.table.horizontalHeader().setStretchLastSection(True)
        self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.table.resizeRowsToContents()
        self.table.resizeColumnsToContents()
        self.table.setColumnWidth(0,350)
                    #self.statusBar().showMessage("Loaded %s" % path, 2000)
    def ClickAction_table(self,index):
        #self.system
        #index.data()
        #self.table.selectedIndexes()[0].data()
        tempstr = self.table.selectedIndexes()[0].data().split()
        filepath = r"PyStudy_web\\example\\기본예제\\"+tempstr[0]+".html"
        selectedRowKey = self.table.selectedIndexes()[0].row()+1#mysql 테이블 줄수 차이
        #print("click test ",selectedRowKey )
        con = sqlite3.connect("mystudy.db")
        cur = con.cursor()
        cur.execute("update 'study' set 'readcheck'=1 where key="+str(selectedRowKey)+";")
        con.commit()
        con.close()
        self.setupViews()
        self.readDB()

        self.system.sendMessage("/학습창 열기 "+filepath)
    def ClickAction_dbinit(self,index):
        con = sqlite3.connect("mystudy.db")
        cur = con.cursor()
        cur.execute("update 'study' set 'readcheck'=0 ;")
        con.commit()
        con.close()
        self.setupViews()
        self.readDB()
开发者ID:louisraccoon,项目名称:PyStudy,代码行数:104,代码来源:StudyPlan.py

示例3: SqliteDbTableEditer

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import selectedIndexes [as 别名]

#.........这里部分代码省略.........
                cbb.addItems(self.SqliteDbTypes)
                cbb.setCurrentIndex(2)
                cbb.setToolTip(
                    '此字段的数据类型不是sqlite标准数据'+
                    '类型,请设置其存储时的使用的sqlite数据类型')
                layG.addWidget(cbb,i,2)
                self.dlg_InsertRow_Values.append((le,cbb))
            else:
                self.dlg_InsertRow_Values.append((le,self.columnsType[i]))
        layG.setColumnStretch(1,1)
        #layH
        layH=QHBoxLayout()
        lay.addLayout(layH)
        #btnOk
        btnOk=QPushButton('确定')
        btnOk.clicked.connect(self.dlg_InsertRow_btnOk_Clicked)
        layH.addWidget(btnOk)
        #btnCancel
        btnCancel=QPushButton('取消')
        btnCancel.clicked.connect(self.dlg.close)
        layH.addWidget(btnCancel)
        self.dlg.show()
    def dlg_InsertRow_btnOk_Clicked(self,event):
        sqlStr="Insert Into %s Values("%self.CurrentTable
        for item in self.dlg_InsertRow_Values:
            if item[0].text()!='':
                if type(item[1])==QComboBox:
                    print (item[0].text(),item[1].currentText())
                else:
                    print (item[0].text(),item[1])
            else:
                pass
    def btnDeleteRows_Clicked(self,event):
        rs=list(map(lambda x:x.row(),self.tv.selectedIndexes()))
        if len(rs)==0:
            QMessageBox.information(self,'提醒','请先选中至少一行,再点击此按钮!')
            return
        for i in reversed(rs):
            self.model.removeRows(i,1)
        self.model.submitAll()
    def btnQuery_Clicked(self,event):
        sqltxt,ok=QInputDialog.getText(self,'查询语句设置',
           '参照创建此表的Sql字符串:\n'+self.sqlStr+
           '\n请输入要设置到self.model的查询语句:')
        if ok:
            self.model.setTable('')
            self.model.setQuery(QSqlQuery(sqltxt))
            self.model.select()
    #----------------------------------------------------------------
    def btnAddColumn_Clicked(self,event):
        self.dlgMake_AddColumn()
    def dlgMake_AddColumn(self,lay=None):
        if lay is None:
            self.dlg=QDialog(self)
            self.dlg.setWindowTitle('添加列:')
        else:
            ##self.grpAddColumn
            self.grpAddColumn=QGroupBox('添加列:')
            self.grpAddColumn.setCheckable(True)
            self.grpAddColumn.setChecked(True)
            lay.addWidget(self.grpAddColumn)
	###layAddColumn
        layAddColumn=QVBoxLayout()
        if lay is None:
            self.dlg.setLayout(layAddColumn)
        else:
开发者ID:winsomexiao,项目名称:PyDemo,代码行数:70,代码来源:sqllite.py

示例4: SubtitleEditor

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import selectedIndexes [as 别名]

#.........这里部分代码省略.........

        # calculate correct minimum subtitle start time
        if subNo > 0:
            timeStart = data.subtitles[subNo - 1].end + minFrameTime
        else:
            timeStart = FrameTime(fps, frames = 0)

        # calculate correct maximum subtitle end time
        if subNo < data.subtitles.size():
            try:
                timeEnd = data.subtitles[subNo].start - minFrameTime
            except SubException:
                timeEnd = FrameTime(fps, frames = 0)
        else:
            timeEnd = timeStart + FrameTime(fps, frames = 50)

        # add subtitle to DataModel
        sub = Subtitle(timeStart, timeEnd, "")
        command = AddSubtitle(self.filePath, subNo, sub)
        with DisableSignalling(self._subtitleData.subtitlesAdded, self._subtitlesAdded):
            self._subtitleData.execute(command)

        # create subtitle graphical representation in editor sub list
        row = createRow(sub)
        self._model.insertRow(subNo, row)
        index = self._model.index(subNo, 2)
        self._subList.clearSelection()
        self._subList.setCurrentIndex(index)
        self._subList.edit(index)

    def addNewSubtitle(self):
        data = self.data
        subNo = data.subtitles.size()
        indices = self._subList.selectedIndexes()
        if len(indices) > 0:
            rows = [index.row() for index in indices]
            subNo = max(rows) + 1
        self._createNewSubtitle(data, subNo)

    def insertNewSubtitle(self):
        data = self.data
        subNo = 0
        indices = self._subList.selectedIndexes()
        if len(indices) > 0:
            rows = [index.row() for index in indices]
            subNo = max(rows)
        self._createNewSubtitle(data, subNo)

    def removeSelectedSubtitles(self):
        indices = self._subList.selectedIndexes()
        if len(indices) > 0:
            rows = list(set([index.row() for index in indices]))
            command = RemoveSubtitles(self.filePath, rows)
            self._subtitleData.execute(command)
            if self._model.rowCount() > rows[-1]:
                self._subList.selectRow(rows[-1])
            else:
                self._subList.selectRow(self._model.rowCount() - 1)

    def highlight(self):
        self._searchBar.show()
        self._searchBar.highlight()

    def showContextMenu(self):
        self._contextMenu.exec(QCursor.pos())
开发者ID:mgoral,项目名称:subconvert,代码行数:69,代码来源:SubtitleTabs.py


注:本文中的PyQt5.QtWidgets.QTableView.selectedIndexes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。