本文整理汇总了Python中PyQt5.QtWidgets.QTableView.setDragEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setDragEnabled方法的具体用法?Python QTableView.setDragEnabled怎么用?Python QTableView.setDragEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.setDragEnabled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setDragEnabled [as 别名]
class MainWindow(QMainWindow):
def __init__(self,system):
super(MainWindow, self).__init__()
self.system = system
fileMenu = QMenu("&Menu", self)
dbinitAction = fileMenu.addAction("사용자 정보 초기화")
quitAction = fileMenu.addAction("E&xit")
quitAction.setShortcut("Ctrl+Q")
self.menuBar().addMenu(fileMenu)
self.statusBar()
dbinitAction.triggered.connect(self.ClickAction_dbinit)
quitAction.triggered.connect(QApplication.instance().quit)
self.setupModel()
self.setupViews()
self.readDB()
self.setWindowTitle("PyStudy 학습진도창")
self.resize(870, 550)
def setupModel(self):
self.model = QStandardItemModel(3, 2, self)
self.model.setHeaderData(0, Qt.Horizontal, "목록")
self.model.setHeaderData(1, Qt.Horizontal, "읽기여부")
self.model2 = QStandardItemModel(3, 2, self)
self.model2.setHeaderData(0, Qt.Horizontal, "학습여부")
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)
#.........这里部分代码省略.........