本文整理汇总了Python中PyQt4.QtGui.QListView.setModelColumn方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.setModelColumn方法的具体用法?Python QListView.setModelColumn怎么用?Python QListView.setModelColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QListView
的用法示例。
在下文中一共展示了QListView.setModelColumn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: widget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setModelColumn [as 别名]
def widget(self,parent):
td = ListPickerDialog(self, parent)
td.setWindowTitle("Select Server")
td.setAttribute(Qt.WA_DeleteOnClose)
layout = QHBoxLayout();
layout.setContentsMargins(16, 0, 16, 8)
view = self.view()
if not view:
listView = QListView()
listView.setEditTriggers( QAbstractItemView.NoEditTriggers)
listView.setModel(self.model())
listView.setModelColumn(self.modelColumn())
if listView.sizeHintForRow(0)>0:
listView.setMinimumHeight(listView.sizeHintForRow(0) * 5)
view = listView
else:
view.setModel(self.model())
layout.addWidget(view)
self.setView(view)
if self.model():
index = self.model().index(self.currentIndex(), self.modelColumn())
self.selectModelIndex(index)
btnbox = QDialogButtonBox(Qt.Vertical)
btnbox.addButton("Select", QDialogButtonBox.AcceptRole)
addBtn = btnbox.addButton("Add", QDialogButtonBox.ActionRole)
addBtn.clicked.connect(self.addServer)
editBtn = btnbox.addButton("Edit", QDialogButtonBox.ActionRole)
editBtn.clicked.connect(self.editServer)
remBtn = btnbox.addButton("Remove", QDialogButtonBox.ActionRole)
remBtn.clicked.connect(self.remServer)
btnbox.accepted.connect( td.accept)
btnbox.rejected.connect( td.reject)
layout.addWidget(btnbox)
td.setLayout(layout)
return td
示例2: QtListControl
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setModelColumn [as 别名]
class QtListControl(QtControl, ProxyListControl):
""" A Qt implementation of an Enaml ProxyListControl.
"""
#: A reference to the widget created by the proxy.
widget = Typed(QListView)
#--------------------------------------------------------------------------
# Initialization API
#--------------------------------------------------------------------------
def create_widget(self):
""" Create the underlying widget.
"""
self.widget = QListView(self.parent_widget())
def init_widget(self):
""" Create and initialize the underlying control.
"""
super(QtListControl, self).init_widget()
d = self.declaration
self.set_item_model(d.item_model)
self.set_model_column(d.model_column)
self.set_view_mode(d.view_mode)
self.set_resize_mode(d.resize_mode)
self.set_flow_mode(d.flow_mode)
self.set_item_wrap(d.item_wrap)
self.set_word_wrap(d.word_wrap)
self.set_item_spacing(d.item_spacing)
self.set_icon_size(d.icon_size)
self.set_uniform_item_sizes(d.uniform_item_sizes)
self.set_layout_mode(d.layout_mode)
self.set_batch_size(d.batch_size)
#--------------------------------------------------------------------------
# Signal Handlers
#--------------------------------------------------------------------------
# def on_item_changed(self, item):
# """ The signal handler for the `itemChanged` signal.
# This handler forwards the call to the item that was changed.
# """
# owner = getattr(item, 'item_owner', None)
# if owner is not None:
# owner.on_changed()
# def on_item_clicked(self, item):
# """ The signal handler for the `itemClicked` signal.
# This handler forwards the call to the item that was clicked.
# """
# owner = getattr(item, 'item_owner', None)
# if owner is not None:
# owner.on_clicked()
# def on_item_double_clicked(self, item):
# """ The signal handler for the `itemDoubleClicked` signal.
# This handler forwards the call to the item that was clicked.
# """
# owner = getattr(item, 'item_owner', None)
# if owner is not None:
# owner.on_double_clicked()
#--------------------------------------------------------------------------
# ProxyListControl API
#--------------------------------------------------------------------------
def set_item_model(self, model):
""" Set the item model for the widget.
"""
if model is None:
self.widget.setModel(None)
else:
self.widget.setModel(QItemModelWrapper(model))
def set_model_column(self, column):
""" Set the model column for the widget.
"""
self.widget.setModelColumn(column)
def set_view_mode(self, mode):
""" Set the view mode of the underlying control.
"""
# Always set static movement for now. This can be revisited in
# the future if the need arises to support movable items.
widget = self.widget
widget.setViewMode(VIEW_MODES[mode])
widget.setMovement(QListView.Static)
def set_resize_mode(self, mode):
""" Set the resize mode of the underlying control.
"""
#.........这里部分代码省略.........
示例3: Browser
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setModelColumn [as 别名]
class Browser(QWidget):
entrytype = type("EntryType", (object,), dict((v,k) for k,v in enumerate(
["directory", "playlist", "mediafile", "url"]
)))
col = type("BrowserColumns", (object,), dict((v,k) for k,v in enumerate(
["name", "last_modified", "entrytype", "uri"]
)))
@staticmethod
def columns():
return len(dict((k,v) for k,v in Browser.col.__dict__.items()
if not k.startswith("__")))
def __init__(self,app):
super(Browser,self).__init__()
self.mpd = app.mpd
self.ih = app.imagehelper
self.model = QStandardItemModel(0,self.columns(),self)
self.initGUI()
self.initActions()
def initGUI(self):
self.setWindowTitle(QApplication.applicationName())
layout = QVBoxLayout()
headerlayout = QHBoxLayout()
homeBtn = QToolButton()
homeBtn.setIcon(self.ih.homeButton)
homeBtn.setFixedSize(64,64)
homeBtn.clicked.connect(self.home)
headerlayout.addWidget(homeBtn)
label = QLabel("<b>Location</b>")
label.setMargin(10)
label.setFixedSize(label.sizeHint())
headerlayout.addWidget(label)
self.currentLocation = ClickableLabel("")
self.currentLocation.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
self.currentLocation.setWordWrap(True)
self.currentLocation.setFixedSize(400,64)
self.currentLocation.clicked.connect(self.back)
headerlayout.addWidget(self.currentLocation)
headerlayout.addStretch()
layout.addLayout(headerlayout)
self.view = QListView()
self.view.setSelectionMode( QAbstractItemView.SingleSelection)
self.view.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.view.setContextMenuPolicy(Qt.CustomContextMenu)
self.view.customContextMenuRequested.connect(self.contextMenu)
self.view.setModel(self.model)
self.view.setModelColumn(0)
#self.view.doubleClicked.connect(self.doubleClicked)
self.view.activated.connect(self.activated)
layout.addWidget(self.view)
self.setLayout(layout)
def initActions(self):
self.actionAdd = QAction("Add", self)
self.actionAddPlay = QAction("Add and Play", self)
self.actionInsert = QAction("Insert", self)
self.actionReplace = QAction("Replace", self)
self.actionReplacePlay = QAction("Replace and Play", self)
self.actionUpdate = QAction("Update", self)
self.actionUpdateAll = QAction("Update all", self)
# playlist actions
self.actionPlsRename = QAction("Rename", self)
self.actionPlsDelete = QAction("Delete", self)
def contextMenu(self,pos):
if self.model.rowCount() == 0: return
mi = self.view.selectionModel().currentIndex()
if not mi.isValid(): return
uri = self.model.item(mi.row(),self.col.uri).text()
entrytype = int(self.model.item(mi.row(),self.col.entrytype).text())
addfunc = None
if entrytype != self.entrytype.playlist:
addfunc = self.mpd.add
else:
addfunc = self.mpd.load
popup = QMenu()
popup.addAction(self.actionAdd)
popup.addAction(self.actionAddPlay)
if entrytype == self.entrytype.mediafile or \
entrytype == self.entrytype.url:
popup.addAction(self.actionInsert)
popup.addAction(self.actionReplace)
popup.addAction(self.actionReplacePlay)
if entrytype == self.entrytype.playlist:
popup.addAction(self.actionPlsRename)
popup.addAction(self.actionPlsDelete)
else:
popup.addAction(self.actionUpdate)
popup.addAction(self.actionUpdateAll)
action = popup.exec_(self.mapToGlobal(pos))
status = self.mpd.status()
#.........这里部分代码省略.........