本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.setItemsExpandable方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.setItemsExpandable方法的具体用法?Python QTreeWidget.setItemsExpandable怎么用?Python QTreeWidget.setItemsExpandable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.setItemsExpandable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setItemsExpandable [as 别名]
class MainWindow(QMainWindow):
def __init__(self, screen_height, screen_width, version, parent=None):
super(MainWindow, self).__init__(parent)
self.screen_width = screen_width
self.screen_height = screen_height
self.version = version
# basic main window settings
self.resize(MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT)
self.setWindowTitle('Linguistica {}'.format(self.version))
# lexicon and lexicon tree
self.lexicon = None
self.lexicon_tree = None
self.initialize_lexicon_tree()
# set up major display, parameter window, then load main window
self.majorDisplay = QWidget()
self.parameterWindow = QWidget()
self.load_main_window()
# 'File' menu and actions
select_corpus_action = self.create_action(text='&Select corpus...',
slot=self.corpus_dir_dialog,
tip='Select a corpus file',
shortcut='Ctrl+N')
select_wordlist_action = self.create_action(text='&Select wordlist...',
slot=self.wordlist_dir_dialog,
tip='Select a wordlist file',
shortcut='Ctrl+W')
run_file_action = self.create_action(text='&Run...',
slot=self.run_file,
tip='Run the input file',
shortcut='Ctrl+D')
parameters_action = self.create_action(text='&Parameters...',
slot=self.parameters_dialog,
tip='Change parameters',
shortcut='Ctrl+P')
file_menu = self.menuBar().addMenu('&File')
file_menu.addAction(select_corpus_action)
file_menu.addAction(select_wordlist_action)
file_menu.addAction(run_file_action)
file_menu.addAction(parameters_action)
self.status = self.statusBar()
self.status.setSizeGripEnabled(False)
self.status.showMessage('No input file loaded. To select one: File --> '
'Select corpus... or Select wordlist...')
def initialize_lexicon_tree(self):
self.lexicon_tree = QTreeWidget()
self.lexicon_tree.setEnabled(True)
self.lexicon_tree.setMinimumWidth(TREEWIDGET_WIDTH_MIN)
self.lexicon_tree.setMaximumWidth(TREEWIDGET_WIDTH_MAX)
self.lexicon_tree.setMinimumHeight(TREEWIDGET_HEIGHT_MIN)
self.lexicon_tree.setHeaderLabel('')
self.lexicon_tree.setItemsExpandable(True)
# noinspection PyUnresolvedReferences
self.lexicon_tree.itemClicked.connect(self.tree_item_clicked)
def create_action(self, text=None, slot=None, tip=None, shortcut=None):
"""
This create actions for the File menu, things like
Read Corpus, Rerun Corpus etc
"""
action = QAction(text, self)
if shortcut:
action.setShortcut(shortcut)
if tip:
action.setToolTip(tip)
action.setStatusTip(tip)
if slot:
# noinspection PyUnresolvedReferences
action.triggered.connect(slot)
if shortcut:
# noinspection PyUnresolvedReferences
QShortcut(QKeySequence(shortcut), self).activated.connect(slot)
return action
def _get_filename_from_dialog(self, ftype='input'):
self.determine_last_file()
if self.last_file_path and self.last_file_type == ftype:
open_dir = self.last_file_path
else:
open_dir = os.getcwd()
# noinspection PyTypeChecker,PyCallByClass
fname = QFileDialog.getOpenFileName(self,
'Select the {} file'.format(ftype),
open_dir)
process_all_gui_events()
# HACK: fname is supposed to be a string (at least according to the
# PyQt5 documentation), but for some reason fname is a tuple.
# So we need this hack to make sure that fname is a string of a filename
# -- Jackson Lee, 2015/06/22
# update: it's turned out that this behavior is due to compatibility
# between PyQt and PySide. The "tuple" behavior is in line with the
#.........这里部分代码省略.........
示例2: ImperiumWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setItemsExpandable [as 别名]
class ImperiumWidget(QWidget):
def __init__(self, parent=None):
super(ImperiumWidget, self).__init__(parent)
# objects, sub-windows
self._world = XNovaWorld_instance()
self._layout = None
self._layout_topbuttons = None
self._tree = None
self._btn_reload = None
# initialization
self.setup_ui()
def setup_ui(self):
self._layout = QVBoxLayout()
self.setLayout(self._layout)
# create layout for top line of buttons
self._layout_topbuttons = QHBoxLayout()
self._layout.addLayout(self._layout_topbuttons)
# create reload button
self._btn_reload = QPushButton(self.tr('Refresh imperium'), self)
self._btn_reload.setIcon(QIcon(':i/reload.png'))
self._btn_reload.clicked.connect(self.on_btn_refresh_imperium)
self._layout_topbuttons.addWidget(self._btn_reload)
# finalize top buttons layout
self._layout_topbuttons.addStretch()
# create tree
self._tree = QTreeWidget(self)
self._tree.setAnimated(False)
self._tree.setExpandsOnDoubleClick(True)
self._tree.setHeaderHidden(False)
self._tree.setItemsExpandable(True)
self._tree.setRootIsDecorated(True)
self._tree.setSortingEnabled(False)
self._tree.setColumnCount(1)
self._tree.setHeaderLabels(['None'])
self._layout.addWidget(self._tree)
self._tree.show()
# called once after full world load
def update_planets(self):
def additem_helper(item_texts, twi_parent=None, align_flag=0):
# align_flag = Qt::AlignLeft / Qt::AlignRight / Qt::AlignHCenter
if align_flag == 0:
align_flag = Qt.AlignHCenter | Qt.AlignVCenter
twi = QTreeWidgetItem(item_texts)
for it_col in range(len(item_texts)):
if it_col > 0:
# void QTreeWidgetItem::setTextAlignment(int column, int alignment)
twi.setTextAlignment(it_col, align_flag)
if twi_parent is None:
self._tree.addTopLevelItem(twi)
else:
twi_parent.addChild(twi)
return True
self._tree.clear() # clear the tree first
planets = self._world.get_planets() # get planets from the world
#
# setup header and its labels
header_labels = ['-']
for i in range(len(planets)):
header_labels.append(planets[i].name)
header_labels.append(self.tr('Total')) # last column - totals
self._tree.setHeaderLabels(header_labels)
# alignment of text in header labels
self._tree.header().setDefaultAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
# default column widths
for i in range(len(planets)):
if i < 1:
self._tree.setColumnWidth(i, 150)
else:
self._tree.setColumnWidth(i, 75)
#
# planets names
item_strings = [self.tr('Name')]
for pl in planets:
item_strings.append(pl.name)
additem_helper(item_strings)
#
# planets coords
item_strings = [self.tr('Coords')]
for pl in planets:
item_strings.append('[{0}:{1}:{2}]'.format(pl.coords.galaxy, pl.coords.system, pl.coords.position))
additem_helper(item_strings)
#
# planets fields
item_strings = [self.tr('Fields')]
total_busy = 0
total_fields = 0
for pl in planets:
total_busy += pl.fields_busy
total_fields = pl.fields_total
item_strings.append('{0} / {1}'.format(pl.fields_busy, pl.fields_total))
item_strings.append('{0} / {1}'.format(total_busy, total_fields))
additem_helper(item_strings)
#
# resources
res_root = QTreeWidgetItem([self.tr('Resources')])
item_strings = [self.tr('Metal')]
total_res = 0
#.........这里部分代码省略.........