本文整理汇总了Python中PyQt4.Qt.QTreeWidgetItem.setSelected方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidgetItem.setSelected方法的具体用法?Python QTreeWidgetItem.setSelected怎么用?Python QTreeWidgetItem.setSelected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QTreeWidgetItem
的用法示例。
在下文中一共展示了QTreeWidgetItem.setSelected方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setSelected [as 别名]
def __init__(self, window, msg, formats):
'''
formats is a list of tuples: [(format, exists, convertible)].
format: Lower case format identifier. E.G. mobi
exists: String representing the number of books that
exist in the format.
convertible: True if the format is a convertible format.
formats should be ordered in the device's preferred format ordering.
'''
QDialog.__init__(self, window)
Ui_ChooseFormatDeviceDialog.__init__(self)
self.setupUi(self)
self.formats.activated[QModelIndex].connect(self.activated_slot)
self.msg.setText(msg)
for i, (format, exists, convertible) in enumerate(formats):
t_item = QTreeWidgetItem()
t_item.setIcon(0, file_icon_provider().icon_from_ext(format.lower()))
t_item.setText(0, format.upper())
t_item.setText(1, exists)
if convertible:
t_item.setIcon(2, QIcon(I('ok.png')))
self.formats.addTopLevelItem(t_item)
if i == 0:
self.formats.setCurrentItem(t_item)
t_item.setSelected(True)
self.formats.resizeColumnToContents(2)
self.formats.resizeColumnToContents(1)
self.formats.resizeColumnToContents(0)
self.formats.header().resizeSection(0, self.formats.header().sectionSize(0) * 2)
self._format = None
示例2: create_folder
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setSelected [as 别名]
def create_folder(self, item):
text, ok = QInputDialog.getText(self, _('Folder name'), _('Enter a name for the new folder'))
if ok and unicode(text):
c = QTreeWidgetItem(item, (unicode(text),))
c.setIcon(0, QIcon(I('mimetypes/dir.png')))
for item in self.folders.selectedItems():
item.setSelected(False)
c.setSelected(True)
self.folders.setCurrentItem(c)
示例3: ChooseFolder
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setSelected [as 别名]
class ChooseFolder(Dialog): # {{{
def __init__(self, msg=None, parent=None):
self.msg = msg
Dialog.__init__(self, _('Choose folder'), 'choose-folder', parent=parent)
def setup_ui(self):
self.l = l = QVBoxLayout(self)
self.setLayout(l)
self.msg = m = QLabel(self.msg or _(
'Choose the folder into which the files will be placed'))
l.addWidget(m)
m.setWordWrap(True)
self.folders = f = QTreeWidget(self)
f.setHeaderHidden(True)
f.itemDoubleClicked.connect(self.accept)
l.addWidget(f)
self.root = QTreeWidgetItem(f, ('/',))
def process(node, parent):
parent.setIcon(0, QIcon(I('mimetypes/dir.png')))
for child in sorted(node, key=sort_key):
c = QTreeWidgetItem(parent, (child,))
process(node[child], c)
process(create_folder_tree(current_container()), self.root)
self.root.setSelected(True)
f.expandAll()
l.addWidget(self.bb)
def folder_path(self, item):
ans = []
while item is not self.root:
ans.append(unicode(item.text(0)))
item = item.parent()
return tuple(reversed(ans))
@property
def chosen_folder(self):
try:
return '/'.join(self.folder_path(self.folders.selectedItems()[0]))
except IndexError:
return ''
示例4: ChooseFolder
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setSelected [as 别名]
class ChooseFolder(Dialog): # {{{
def __init__(self, msg=None, parent=None):
self.msg = msg
Dialog.__init__(self, _('Choose folder'), 'choose-folder', parent=parent)
def setup_ui(self):
self.l = l = QVBoxLayout(self)
self.setLayout(l)
self.msg = m = QLabel(self.msg or _(
'Choose the folder into which the files will be placed'))
l.addWidget(m)
m.setWordWrap(True)
self.folders = f = QTreeWidget(self)
f.setHeaderHidden(True)
f.itemDoubleClicked.connect(self.accept)
l.addWidget(f)
f.setContextMenuPolicy(Qt.CustomContextMenu)
f.customContextMenuRequested.connect(self.show_context_menu)
self.root = QTreeWidgetItem(f, ('/',))
def process(node, parent):
parent.setIcon(0, QIcon(I('mimetypes/dir.png')))
for child in sorted(node, key=sort_key):
c = QTreeWidgetItem(parent, (child,))
process(node[child], c)
process(create_folder_tree(current_container()), self.root)
self.root.setSelected(True)
f.expandAll()
l.addWidget(self.bb)
def show_context_menu(self, point):
item = self.folders.itemAt(point)
if item is None:
return
m = QMenu(self)
m.addAction(QIcon(I('mimetypes/dir.png')), _('Create new folder'), partial(self.create_folder, item))
m.popup(self.folders.mapToGlobal(point))
def create_folder(self, item):
text, ok = QInputDialog.getText(self, _('Folder name'), _('Enter a name for the new folder'))
if ok and unicode(text):
c = QTreeWidgetItem(item, (unicode(text),))
c.setIcon(0, QIcon(I('mimetypes/dir.png')))
for item in self.folders.selectedItems():
item.setSelected(False)
c.setSelected(True)
self.folders.setCurrentItem(c)
def folder_path(self, item):
ans = []
while item is not self.root:
ans.append(unicode(item.text(0)))
item = item.parent()
return tuple(reversed(ans))
@property
def chosen_folder(self):
try:
return '/'.join(self.folder_path(self.folders.selectedItems()[0]))
except IndexError:
return ''