本文整理汇总了Python中PyQt4.QtGui.QListView.setSelectionMode方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.setSelectionMode方法的具体用法?Python QListView.setSelectionMode怎么用?Python QListView.setSelectionMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QListView
的用法示例。
在下文中一共展示了QListView.setSelectionMode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setSelectionMode [as 别名]
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
view = QListView()
view.setDragEnabled(True)
view.setAcceptDrops(True)
view.setDropIndicatorShown(True)
view.setSelectionMode(view.ExtendedSelection)
self.model = ListModel(view)
view.setModel(self.model)
self.setCentralWidget(view)
示例2: checkablePopup
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setSelectionMode [as 别名]
def checkablePopup( self ):
"""
Returns the popup if this widget is checkable.
:return <QListView> || None
"""
if ( not self._checkablePopup and self.isCheckable() ):
popup = QListView(self)
popup.setSelectionMode(QListView.NoSelection)
popup.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
popup.setWindowFlags(Qt.Popup)
popup.installEventFilter(self)
popup.doubleClicked.connect(self.checkModelIndex)
self._checkablePopup = popup
return self._checkablePopup
示例3: Browser
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setSelectionMode [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()
#.........这里部分代码省略.........
示例4: OWQualityControl
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setSelectionMode [as 别名]
class OWQualityControl(widget.OWWidget):
name = "Quality Control"
description = "Experiment quality control"
icon = "../widgets/icons/QualityControl.svg"
priority = 5000
inputs = [("Experiment Data", Orange.data.Table, "set_data")]
outputs = []
DISTANCE_FUNCTIONS = [("Distance from Pearson correlation",
dist_pcorr),
("Euclidean distance",
dist_eucl),
("Distance from Spearman correlation",
dist_spearman)]
settingsHandler = SetContextHandler()
split_by_labels = settings.ContextSetting({})
sort_by_labels = settings.ContextSetting({})
selected_distance_index = settings.Setting(0)
def __init__(self, parent=None):
super().__init__(parent)
## Attributes
self.data = None
self.distances = None
self.groups = None
self.unique_pos = None
self.base_group_index = 0
## GUI
box = gui.widgetBox(self.controlArea, "Info")
self.info_box = gui.widgetLabel(box, "\n")
## Separate By box
box = gui.widgetBox(self.controlArea, "Separate By")
self.split_by_model = itemmodels.PyListModel(parent=self)
self.split_by_view = QListView()
self.split_by_view.setSelectionMode(QListView.ExtendedSelection)
self.split_by_view.setModel(self.split_by_model)
box.layout().addWidget(self.split_by_view)
self.split_by_view.selectionModel().selectionChanged.connect(
self.on_split_key_changed)
## Sort By box
box = gui.widgetBox(self.controlArea, "Sort By")
self.sort_by_model = itemmodels.PyListModel(parent=self)
self.sort_by_view = QListView()
self.sort_by_view.setSelectionMode(QListView.ExtendedSelection)
self.sort_by_view.setModel(self.sort_by_model)
box.layout().addWidget(self.sort_by_view)
self.sort_by_view.selectionModel().selectionChanged.connect(
self.on_sort_key_changed)
## Distance box
box = gui.widgetBox(self.controlArea, "Distance Measure")
gui.comboBox(box, self, "selected_distance_index",
items=[name for name, _ in self.DISTANCE_FUNCTIONS],
callback=self.on_distance_measure_changed)
self.scene = QGraphicsScene()
self.scene_view = QGraphicsView(self.scene)
self.scene_view.setRenderHints(QPainter.Antialiasing)
self.scene_view.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
self.mainArea.layout().addWidget(self.scene_view)
self.scene_view.installEventFilter(self)
self._disable_updates = False
self._cached_distances = {}
self._base_index_hints = {}
self.main_widget = None
self.resize(800, 600)
def clear(self):
"""Clear the widget state."""
self.data = None
self.distances = None
self.groups = None
self.unique_pos = None
with disable_updates(self):
self.split_by_model[:] = []
self.sort_by_model[:] = []
self.main_widget = None
self.scene.clear()
self.info_box.setText("\n")
self._cached_distances = {}
def set_data(self, data=None):
"""Set input experiment data."""
self.closeContext()
self.clear()
#.........这里部分代码省略.........
示例5: RatingWidget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setSelectionMode [as 别名]
class RatingWidget(QWidget):
"""
Last panel. Gives point cost of idea set and lists any penalty flags.
"""
def __init__(self, parent=None):
super().__init__(parent=parent)
# cost display
self.cost = QGroupBox("National ideas")
costLayout = QFormLayout()
self.costRating = QLineEdit()
self.costRating.setReadOnly(True)
costLayout.addRow(QLabel("Rating:"), self.costRating)
self.costDisplay = QLineEdit()
self.costDisplay.setReadOnly(True)
costLayout.addRow(QLabel("Cost:"), self.costDisplay)
possibleRatings = QGroupBox("Possible ratings")
possibleRatingsLayout = QFormLayout()
for cost, rating in ideaRatings:
if cost is not None:
possibleRatingsLayout.addRow(QLabel("Up to %0.1f:" % (cost),), QLabel(rating))
else:
possibleRatingsLayout.addRow(QLabel("Above:"), QLabel(rating))
possibleRatings.setLayout(possibleRatingsLayout)
costLayout.addRow(possibleRatings)
breakdown = QGroupBox("Breakdown")
breakdownLayout = QFormLayout()
self.breakdownLabels = []
self.breakdownCosts = []
for i in range(9):
breakdownLabel = QLabel()
self.breakdownLabels.append(breakdownLabel)
breakdownCost = QLineEdit()
breakdownCost.setReadOnly(True)
self.breakdownCosts.append(breakdownCost)
breakdownLayout.addRow(breakdownLabel, breakdownCost)
breakdown.setLayout(breakdownLayout)
costLayout.addRow(breakdown)
self.cost.setLayout(costLayout)
self.cost.setToolTip(costToolTipText)
# penalty display
self.penalties = QGroupBox("Penalties")
penaltiesLayout = QFormLayout()
# self.penaltiesRating = QLineEdit()
# self.penaltiesRating.setReadOnly(True)
# penaltiesLayout.addRow(QLabel("Rating:"), self.penaltiesRating)
self.yellowCardCount = QLineEdit()
self.yellowCardCount.setReadOnly(True)
penaltiesLayout.addRow(QLabel("Yellow cards:"), self.yellowCardCount)
self.yellowCardDisplay = QListView()
self.yellowCardDisplay.setSelectionMode(QAbstractItemView.NoSelection)
self.yellowCards = QStringListModel()
self.yellowCardDisplay.setModel(self.yellowCards)
penaltiesLayout.addRow(self.yellowCardDisplay)
self.redCardCount = QLineEdit()
self.redCardCount.setReadOnly(True)
penaltiesLayout.addRow(QLabel("Red cards:"), self.redCardCount)
self.redCardDisplay = QListView()
self.redCardDisplay.setSelectionMode(QAbstractItemView.NoSelection)
self.redCards = QStringListModel()
self.redCardDisplay.setModel(self.redCards)
penaltiesLayout.addRow(self.redCardDisplay)
self.penalties.setLayout(penaltiesLayout)
self.penalties.setToolTip(penaltiesToolTipText)
layout = QHBoxLayout()
layout.addWidget(self.cost)
layout.addWidget(self.penalties)
self.setLayout(layout)
def handleCostChanged(self, costs):
totalCost = sum(costs)
self.costDisplay.setText("%0.2f" % (totalCost,))
self.costRating.setText(getIdeaRating(totalCost))
for i, cost in enumerate(costs):
self.breakdownCosts[i].setText("%0.2f" % cost)
def handleIdeaNamesChanged(self, names):
for i, name in enumerate(names):
self.breakdownLabels[i].setText(name)
#.........这里部分代码省略.........
示例6: OWDataSort
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setSelectionMode [as 别名]
class OWDataSort(OWWidget):
contextHandlers = {
"": DomainContextHandler(
"", ["sortroles"]
)
}
settingsList = ["autoCommit"]
def __init__(self, parent=None, signalManger=None, title="Data Sort"):
super(OWDataSort, self).__init__(parent, signalManger, title,
wantMainArea=False)
#: Mapping (feature.name, feature.var_type) to (sort_index, sort_order)
#: where sirt index is the position of the feature in the sortByModel
#: and sort_order the Qt.SortOrder flag
self.sortroles = {}
self.autoCommit = False
self._outputChanged = False
box = OWGUI.widgetBox(self.controlArea, "Sort By Features")
self.sortByView = QListView()
self.sortByView.setItemDelegate(SortParamDelegate(self))
self.sortByView.setSelectionMode(QListView.ExtendedSelection)
self.sortByView.setDragDropMode(QListView.DragDrop)
self.sortByView.setDefaultDropAction(Qt.MoveAction)
self.sortByView.viewport().setAcceptDrops(True)
self.sortByModel = VariableListModel(
flags=Qt.ItemIsEnabled | Qt.ItemIsSelectable |
Qt.ItemIsDragEnabled | Qt.ItemIsEditable
)
self.sortByView.setModel(self.sortByModel)
box.layout().addWidget(self.sortByView)
box = OWGUI.widgetBox(self.controlArea, "Unused Features")
self.unusedView = QListView()
self.unusedView.setSelectionMode(QListView.ExtendedSelection)
self.unusedView.setDragDropMode(QListView.DragDrop)
self.unusedView.setDefaultDropAction(Qt.MoveAction)
self.unusedView.viewport().setAcceptDrops(True)
self.unusedModel = VariableListModel(
flags=Qt.ItemIsEnabled | Qt.ItemIsSelectable |
Qt.ItemIsDragEnabled
)
self.unusedView.setModel(self.unusedModel)
box.layout().addWidget(self.unusedView)
box = OWGUI.widgetBox(self.controlArea, "Output")
cb = OWGUI.checkBox(box, self, "autoCommit", "Auto commit")
b = OWGUI.button(box, self, "Commit", callback=self.commit)
OWGUI.setStopper(self, b, cb, "_outputChanged", callback=self.commit)
def setData(self, data):
"""
Set the input data.
"""
self._storeRoles()
self.closeContext("")
self.data = data
if data is not None:
self.openContext("", data)
domain = data.domain
features = (domain.variables + domain.class_vars +
domain.get_metas().values())
sort_by = []
unused = []
for feat in features:
hint = self.sortroles.get((feat.name, feat.var_type), None)
if hint is not None:
index, order = hint
sort_by.append((feat, index, order))
else:
unused.append(feat)
sort_by = sorted(sort_by, key=itemgetter(1))
self.sortByModel[:] = [feat for feat, _, _ in sort_by]
self.unusedModel[:] = unused
# Restore the sort orders
for i, (_, _, order) in enumerate(sort_by):
index = self.sortByModel.index(i, 0)
self.sortByModel.setData(index, order, SortOrderRole)
self.commit()
def _invalidate(self):
if self.autoCommit:
self.commit()
else:
self._outputChanged = True
def _sortingParams(self):
params = []
#.........这里部分代码省略.........
示例7: OrderSelectorView
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setSelectionMode [as 别名]
class OrderSelectorView(QObject):
""""""
#----------------------------------------------------------------------
def __init__(self, parentWidget,
label_text_NotSelected, label_text_Selected,
model):
"""Constructor"""
QObject.__init__(self)
self.model = model
self.gridLayout = QGridLayout(parentWidget)
self.verticalLayout_left_list = QVBoxLayout()
self.label_NotSelected = QLabel(parentWidget)
self.label_NotSelected.setText(label_text_NotSelected)
self.verticalLayout_left_list.addWidget(self.label_NotSelected)
self.listView_NotSelected = QListView(parentWidget)
self.verticalLayout_left_list.addWidget(self.listView_NotSelected)
self.gridLayout.addLayout(self.verticalLayout_left_list, 0, 0, 1, 2)
self.verticalLayout_right_left = QVBoxLayout()
spacerItem = QSpacerItem(20,178,QSizePolicy.Minimum,QSizePolicy.Expanding)
self.verticalLayout_right_left.addItem(spacerItem)
self.pushButton_right_arrow = QPushButton(parentWidget)
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalPolicy(0)
sizePolicy.setHeightForWidth(
self.pushButton_right_arrow.sizePolicy().hasHeightForWidth())
self.pushButton_right_arrow.setSizePolicy(sizePolicy)
self.pushButton_right_arrow.setMinimumSize(QSize(50,50))
self.pushButton_right_arrow.setMaximumSize(QSize(50,50))
self.pushButton_right_arrow.setIcon(QIcon(':/right_arrow.png'))
self.pushButton_right_arrow.setIconSize(QSize(50,50))
self.pushButton_right_arrow.setText('')
self.verticalLayout_right_left.addWidget(self.pushButton_right_arrow)
self.pushButton_left_arrow = QPushButton(parentWidget)
sizePolicy.setHeightForWidth(
self.pushButton_left_arrow.sizePolicy().hasHeightForWidth())
self.pushButton_left_arrow.setSizePolicy(sizePolicy)
self.pushButton_left_arrow.setMinimumSize(QSize(50,50))
self.pushButton_left_arrow.setMaximumSize(QSize(50,50))
self.pushButton_left_arrow.setIcon(QIcon(':/left_arrow.png'))
self.pushButton_left_arrow.setIconSize(QSize(50,50))
self.pushButton_left_arrow.setText('')
self.verticalLayout_right_left.addWidget(self.pushButton_left_arrow)
spacerItem = QSpacerItem(20,178,QSizePolicy.Minimum,QSizePolicy.Expanding)
self.verticalLayout_right_left.addItem(spacerItem)
self.gridLayout.addLayout(self.verticalLayout_right_left, 0, 2, 1, 1)
self.verticalLayout_right_list = QVBoxLayout()
self.label_Selected = QLabel(parentWidget)
self.label_Selected.setText(label_text_Selected)
self.verticalLayout_right_list.addWidget(self.label_Selected)
self.listView_Selected = QListView(parentWidget)
self.verticalLayout_right_list.addWidget(self.listView_Selected)
self.gridLayout.addLayout(self.verticalLayout_right_list, 0, 3, 1, 2)
self.verticalLayout_up_down = QVBoxLayout()
spacerItem = QSpacerItem(20,178,QSizePolicy.Minimum,QSizePolicy.Expanding)
self.verticalLayout_up_down.addItem(spacerItem)
self.pushButton_up_arrow = QPushButton(parentWidget)
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalPolicy(0)
sizePolicy.setHeightForWidth(
self.pushButton_up_arrow.sizePolicy().hasHeightForWidth())
self.pushButton_up_arrow.setSizePolicy(sizePolicy)
self.pushButton_up_arrow.setMinimumSize(QSize(50,50))
self.pushButton_up_arrow.setMaximumSize(QSize(50,50))
self.pushButton_up_arrow.setIcon(QIcon(':/up_arrow.png'))
self.pushButton_up_arrow.setIconSize(QSize(50,50))
self.pushButton_up_arrow.setText('')
self.verticalLayout_up_down.addWidget(self.pushButton_up_arrow)
self.pushButton_down_arrow = QPushButton(parentWidget)
sizePolicy.setHeightForWidth(
self.pushButton_down_arrow.sizePolicy().hasHeightForWidth())
self.pushButton_down_arrow.setSizePolicy(sizePolicy)
self.pushButton_down_arrow.setMinimumSize(QSize(50,50))
self.pushButton_down_arrow.setMaximumSize(QSize(50,50))
self.pushButton_down_arrow.setIcon(QIcon(':/down_arrow.png'))
self.pushButton_down_arrow.setIconSize(QSize(50,50))
self.pushButton_down_arrow.setText('')
self.verticalLayout_up_down.addWidget(self.pushButton_down_arrow)
spacerItem = QSpacerItem(20,178,QSizePolicy.Minimum,QSizePolicy.Expanding)
self.verticalLayout_up_down.addItem(spacerItem)
self.gridLayout.addLayout(self.verticalLayout_up_down, 0, 5, 1, 1)
self.listView_NotSelected.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.listView_Selected.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.listView_NotSelected.setModel(self.model.model_NotSelected)
self.listView_Selected.setModel(self.model.model_Selected)
#----------------------------------------------------------------------
#.........这里部分代码省略.........
示例8: FeedWatchWidget
# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import setSelectionMode [as 别名]
class FeedWatchWidget(QWidget):
def __init__(self):
super(FeedWatchWidget, self).__init__()
self.feedList = AmuleFeedWatcher()
self.eventList = EventServer.events
# Control buttons: check now, add feed, remove feed
checkNowButton = QPushButton('Check feeds now!')
self.connect(checkNowButton, SIGNAL('clicked()'),
self.checkNow)
addFeedButton = QPushButton('Add feed...')
self.connect(addFeedButton, SIGNAL('clicked()'),
self.addFeed)
removeFeedButton = QPushButton('Remove feed...')
self.connect(removeFeedButton, SIGNAL('clicked()'),
self.removeFeed)
buttons = QHBoxLayout()
buttons.addWidget(addFeedButton)
buttons.addWidget(removeFeedButton)
buttons.addStretch()
buttons.addWidget(checkNowButton)
# main layout
layout = QVBoxLayout()
self.feedView = QListView()
self.feedView.setModel(self.feedList)
layout.addWidget(self.feedView)
self.connect(self.feedView, SIGNAL('doubleClicked(const QModelIndex&)'),
self.feedEdit)
layout.addLayout(buttons)
self.eventView = QListView()
self.eventView.setSelectionMode(QAbstractItemView.NoSelection)
self.eventView.setModel(self.eventList)
layout.addWidget(self.eventView)
self.setLayout(layout)
# check for feeds every 2 hours
self.timer = QTimer(self)
self.connect(self.timer, SIGNAL('timeout()'),
self.checkNow)
self.timer.start(2*60*60*1000)
def feedEdit(self, index):
fullFeed = self.feedList.getFullFeedIndex(index.row())
epSelect = EpisodeSelector(fullFeed)
if epSelect.exec_() == QDialog.Accepted:
self.feedList.setLastUpdateIndex(index.row(), epSelect.lastUpdate)
def checkNow(self):
# this can last a while, do not block the UI meanwhile
CheckThread(self, self.feedList).start()
def addFeed(self):
result, ok = QInputDialog.getText(self, 'Add feed...', 'Enter the feed url:', QLineEdit.Normal, '')
if ok and not result.isEmpty():
try:
self.feedList.addFeed(result)
except Exception, e:
QMessageBox.critical(self, 'Add feed...', 'Error: %s' % str(e))