本文整理汇总了Python中PyQt5.QtWidgets.QListView.currentIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.currentIndex方法的具体用法?Python QListView.currentIndex怎么用?Python QListView.currentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QListView
的用法示例。
在下文中一共展示了QListView.currentIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SettingWindow
# 需要导入模块: from PyQt5.QtWidgets import QListView [as 别名]
# 或者: from PyQt5.QtWidgets.QListView import currentIndex [as 别名]
class SettingWindow(QWidget):
# on_addButtonClicked=pyqtSignal()
# on_removeButtonClicked=pyqtSignal()
# on_okButtonClicked=pyqtSignal()
finished=pyqtSignal()
def __init__(self):
QWidget.__init__(self)
self.listview=QListView(self)
self.addButton=QPushButton(self)
self.removeButton=QPushButton(self)
self.resize(630,440)
self.okButton=QPushButton(self)
self.listview.setGeometry(30,30,410,351)
self.addButton.setGeometry(490,40,80,22)
self.addButton.setText("add")
self.addButton.clicked.connect(self.click_add)
self.removeButton.setGeometry(490,80,80,22)
self.removeButton.setText("remove")
self.removeButton.clicked.connect(self.click_remove)
self.okButton.setGeometry(490,150,80,22)
self.okButton.setText("ok")
self.okButton.clicked.connect(self.click_ok)
# self.aw=null
self.fresh()
def click_ok(self):
self.finished.emit()
self.close()
def click_add(self):
self.aw=AddWindow()
self.aw.show()
self.aw.okSig.connect(self.fresh)
def click_remove(self):
self.remove()
def fresh(self):
confFile=open("conf","r")
self.listModel=QStandardItemModel()
self.itemList=cPickle.load(confFile)
confFile.close()
for item in self.itemList:
itemView=QStandardItem(QIcon(item.path),item.name)
itemView.setEditable(False)
self.listModel.appendRow(itemView)
self.listview.setModel(self.listModel)
def remove(self):
index=self.listview.currentIndex().row()
self.itemList.pop(index)
self.listModel.removeRow(index)
confFile=open("conf","w")
cPickle.dump(self.itemList,confFile)
confFile.close()
示例2: DesktopIconWidget
# 需要导入模块: from PyQt5.QtWidgets import QListView [as 别名]
# 或者: from PyQt5.QtWidgets.QListView import currentIndex [as 别名]
#.........这里部分代码省略.........
def createShortcut(self):
d = ShortcutDialog(self)
if self.window().runDialog(d.create) == QDialog.Accepted:
shortcut = d.getResult()
shortcut["id"] = str(uuid.uuid4())
self.quickDesktopModel.addShortcut(shortcut)
d.deleteLater()
def createBookmark(self):
d = BookmarkDialog(self)
if self.window().runDialog(d.create) == QDialog.Accepted:
shortcut = {
"id": str(uuid.uuid4()),
"icon": "",
"openwith": "",
"dir": "",
}
shortcut.update(d.getResult())
self.quickDesktopModel.addShortcut(shortcut)
d.deleteLater()
def createComputerShortcut(self):
shortcut = {
"id": str(uuid.uuid4()),
"name": self.tr("我的电脑"),
"path": COMPUTER_PATH,
"icon": "",
"dir": "",
"openwith": "",
}
self.quickDesktopModel.addShortcut(shortcut)
def createDocumentsShortcut(self):
shortcut = {
"id": str(uuid.uuid4()),
"name": self.tr("我的文档"),
"path": DOCUMENTS_PATH,
"icon": "",
"dir": "",
"openwith": "",
}
self.quickDesktopModel.addShortcut(shortcut)
def createPicturesShortcut(self):
shortcut = {
"id": str(uuid.uuid4()),
"name": self.tr("图片收藏"),
"path": PICTURES_PATH,
"icon": "",
"dir": "",
"openwith": "",
}
self.quickDesktopModel.addShortcut(shortcut)
def createMusicShortcut(self):
shortcut = {
"id": str(uuid.uuid4()),
"name": self.tr("我的音乐"),
"path": MUSIC_PATH,
"icon": "",
"dir": "",
"openwith": "",
}
self.quickDesktopModel.addShortcut(shortcut)
def renameShortcut(self):
self.listView.edit(self.listView.currentIndex())
def removeShortcut(self):
self.quickDesktopModel.removeShortcut(self.listView.currentIndex())
def editShortcut(self):
index = self.listView.currentIndex()
if not index.isValid():
return
shortcut = self.quickDesktopModel.shortcutAt(index)
url = QUrl.fromUserInput(shortcut["path"])
if not url.isValid():
return
if url.scheme() == "special":
QMessageBox.information(self, self.tr("编辑快捷方式"), self.tr("不能编辑特殊图标。"))
return
elif url.scheme() == "file":
d = ShortcutDialog(self)
else:
d = BookmarkDialog(self)
if self.window().runDialog(d.edit, shortcut) == QDialog.Accepted:
shortcut.update(d.getResult())
self.quickDesktopModel.updateShortcut(shortcut, index)
d.deleteLater()
def runQuickDesktopShortcut(self):
index = self.listView.currentIndex()
if not index.isValid():
return
if not self.quickDesktopModel.runShortcut(index):
QMessageBox.information(self, self.tr("快捷面板"), \
self.tr("不能运行快捷方式。请检查文件是否存在或者程序是否正确。"))
else:
self.window().close()