QAbstractTableModel
被指定为ItemDelegate(QItemDelegate)
作为模型。并tableView.openPersistentEditor
分配了QLineEditor
。现在,当单击tableView时,事件不会一直传播到tableView(它是否被委派的QLineEdit's
阻止)。
什么是传递event that is passed through the
mousePressEvent to
ItemDelegate when the tableView's item is clicked even while it is occupied by
QTableView的模型? Is there any
QItemInstance tableView.setSelectionBehavior(QtGui.QTableView.SelectRows)
QItemDelegate`标志的方法用来完成任务?
代码使用model和delegate创建一个tableView。 单击列0或列1触发的事件不会传播到tableView的项目,因为项目保持取消选择状态。
取消注释from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])
class LineEdit(QtGui.QLineEdit):
def __init__(self, parent=None, total=20):
super(LineEdit, self).__init__(parent=parent)
def mousePressEvent(self, event):
print 'mousePressEvent', event
super(LineEdit, self).mousePressEvent(event)
class Delegate(QtGui.QItemDelegate):
def __init__(self):
QtGui.QItemDelegate.__init__(self)
def createEditor(self, parent, option, index):
if index.column()==0:
lineedit=LineEdit(parent)
return lineedit
elif index.column()==1:
combo=QtGui.QComboBox(parent)
return combo
def setEditorData(self, editor, index):
row = index.row()
column = index.column()
value = index.model().items[row][column]
if isinstance(editor, QtGui.QComboBox):
editor.addItems(['Somewhere','Over','The Rainbow'])
editor.setCurrentIndex(index.row())
if isinstance(editor, QtGui.QLineEdit):
editor.setText('Somewhere over the rainbow')
class Model(QtCore.QAbstractTableModel):
def __init__(self):
QtCore.QAbstractTableModel.__init__(self)
self.items = [[1, 'one', 'ONE'], [2, 'two', 'TWO'], [3, 'three', 'THREE']]
def flags(self, index):
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
def rowCount(self, parent=QtCore.QModelIndex()):
return 3
def columnCount(self, parent=QtCore.QModelIndex()):
return 3
def data(self, index, role):
if not index.isValid(): return
row = index.row()
column = index.column()
if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
return self.items[row][column]
def tableViewClicked(index):
print 'clicked: %s'%index
tableModel=Model()
tableView=QtGui.QTableView()
tableView.setModel(tableModel)
tableView.setItemDelegate(Delegate())
# tableView.setSelectionBehavior(QtGui.QTableView.SelectRows)
tableView.clicked.connect(tableViewClicked)
for row in range(tableModel.rowCount()):
for column in range(tableModel.columnCount()):
index=tableModel.index(row, column)
tableView.openPersistentEditor(index)
tableView.show()
app.exec_()
行会解决问题。是吗?
//This container is only visible on devices with 1025px or more such as iPad in landscape or portrait view
@media screen and (min-width: 1025px) {
.desktop-container {
Display:none;
}
}
// This container is only visible on smaller devices with screen size 360px - 1024px
@media screen and (min-width:360px) and (max-width:1024px) {
.mobile-container {
Display:none;
}
}
答案 0 :(得分:1)
为什么不在委托项的功能中使用模型对象指针?例如,将您的委托项目的信号连接到模型的插槽,或者在委托项目的事件处理程序中调用模型的功能?