本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.setHeaderLabel方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.setHeaderLabel方法的具体用法?Python QTreeWidget.setHeaderLabel怎么用?Python QTreeWidget.setHeaderLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.setHeaderLabel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabel [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: OtherPackagesPage
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabel [as 别名]
class OtherPackagesPage(QWidget):
""" The GUI for the other packages page of a project. """
# The page's label.
label = "Other Packages"
@property
def project(self):
""" The project property getter. """
return self._project
@project.setter
def project(self, value):
""" The project property setter. """
if self._project != value:
self._project = value
self._package_delegate.set_project(value)
self._update_page()
def __init__(self):
""" Initialise the page. """
super().__init__()
self._project = None
# Create the page's GUI.
layout = QHBoxLayout()
self._package_selector = QTreeWidget(
whatsThis="This shows a list of directories containing "
"additional Python packages which can be scanned when "
"selected. Double-click on a directory to edit or "
"remove it. Double-click below the last directory in "
"order to add a new one.")
self._package_selector.setHeaderLabel("Packages Directory")
self._package_selector.setEditTriggers(
QTreeWidget.DoubleClicked|QTreeWidget.SelectedClicked|
QTreeWidget.EditKeyPressed)
self._package_selector.setRootIsDecorated(False)
self._package_selector.currentItemChanged.connect(
self._package_selector_changed)
self._package_selector.itemChanged.connect(self._package_dir_changed)
self._package_delegate = FilenameEditorDelegate("Packages Directory",
directory=True)
self._package_selector.setItemDelegateForColumn(0,
self._package_delegate)
layout.addWidget(self._package_selector)
self._package_edit = _PackageDirectoryEditor()
self._package_edit.package_changed.connect(self._package_changed)
package_edit_gb = QGroupBox(self._package_edit.title)
package_edit_gb.setLayout(self._package_edit)
layout.addWidget(package_edit_gb)
self.setLayout(layout)
def _update_page(self):
""" Update the page using the current project. """
project = self.project
self._package_selector.clear()
for package in project.other_packages:
self._add_package_dir(package)
self._add_package_dir()
def _add_package_dir(self, package=None):
""" Add a QTreeWidgetItem that holds a package directory. """
if package is None:
package = QrcPackage()
name = ''
else:
name = package.name
itm = QTreeWidgetItem([name])
itm.setData(0, Qt.UserRole, package)
itm.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled|Qt.ItemNeverHasChildren|Qt.ItemIsEditable)
self._package_selector.addTopLevelItem(itm)
def _package_selector_changed(self, new, old):
""" Invoked when the user selects a package directory. """
if new is not None:
self._package_edit.configure(new.data(0, Qt.UserRole),
self.project)
def _package_dir_changed(self, itm, column):
""" Invoked when the user edits a package directory name. """
#.........这里部分代码省略.........
示例3: QrcPackageEditor
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabel [as 别名]
class QrcPackageEditor(QGridLayout):
""" A resource file system package editor. Note that this is a QLayout and
not a QWidget.
"""
# Emitted when the package has changed.
package_changed = pyqtSignal()
def __init__(self, show_root=False, scan="Scan", scan_whats_this='', whats_this=''):
""" Initialise the editor. """
super().__init__()
self.package = None
self.project = None
self._show_root = show_root
self._package_edit = QTreeWidget(whatsThis=whats_this)
self._package_edit.header().hide()
self._package_edit.itemChanged.connect(self._package_changed)
self.addWidget(self._package_edit, 0, 0, 3, 1)
self._scan_button = QPushButton(scan, whatsThis=scan_whats_this,
clicked=self._scan, enabled=False)
self.addWidget(self._scan_button, 0, 1)
self._remove_button = QPushButton("Remove all",
whatsThis="Remove all of the scanned directories and files.",
clicked=self._remove_all, enabled=False)
self.addWidget(self._remove_button, 0, 2)
self._include_button = QPushButton("Include all",
whatsThis="Select all of the scanned directories and files.",
clicked=self._include_all, enabled=False)
self.addWidget(self._include_button, 1, 1)
self._exclude_button = QPushButton("Exclude all",
whatsThis="Deselect all of the scanned directories and files.",
clicked=self._exclude_all, enabled=False)
self.addWidget(self._exclude_button, 1, 2)
self._exclusions_edit = QTreeWidget(
whatsThis="Any directory or file that matches any of the "
"these patterns will be automatically ignored when "
"scanning. Double-click on a pattern to edit or remove "
"it. Double-click below the last pattern in order to "
"add a new one.")
self._exclusions_edit.setHeaderLabel("Exclusions")
self._exclusions_edit.setEditTriggers(
QTreeWidget.DoubleClicked|QTreeWidget.SelectedClicked|
QTreeWidget.EditKeyPressed)
self._exclusions_edit.setRootIsDecorated(False)
self._exclusions_edit.itemChanged.connect(self._exclusion_changed)
self.addWidget(self._exclusions_edit, 2, 1, 1, 2)
def configure(self, package, project):
""" Configure the editor with the contents of the given package and
project.
"""
# Save the configuration.
self.package = package
self.project = project
# Set the package itself.
self._visualise()
# Set the exclusions.
self._exclusions_edit.clear()
for exclude in package.exclusions:
self._add_exclusion_item(exclude)
# Add one to be edited to create a new entry.
self._add_exclusion_item()
self._scan_button.setEnabled(package is not None)
def get_root_dir(self):
""" Return the root directory to scan, or '' if there was an error or
the user cancelled.
"""
raise NotImplementedError
def filter(self, name):
""" See if a scanned name should be discarded. """
# Include everything by default.
return False
def required(self, name):
""" See if a scanned name is required. """
# Nothing is required by default.
return False
def _add_exclusion_item(self, exclude=''):
#.........这里部分代码省略.........
示例4: EditorConfiguration
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabel [as 别名]
#.........这里部分代码省略.........
vboxg3.addWidget(self._checkErrors)
vboxg3.addWidget(self._showErrorsOnLine)
vboxg3.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding))
formFeatures.addWidget(group3, 2, 0)
# Find PEP8 Errors (highlighter)
vboxg4 = QHBoxLayout(group4)
vboxg4.setContentsMargins(5, 15, 5, 5)
vvbox = QVBoxLayout()
self._checkStyle = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_SHOW_PEP8)
self._checkStyle.setChecked(settings.CHECK_STYLE)
self._checkStyle.stateChanged[int].connect(self._disable_check_style)
vvbox.addWidget(self._checkStyle)
self._checkStyleOnLine = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_SHOW_TOOLTIP_PEP8)
self._checkStyleOnLine.setChecked(settings.CHECK_HIGHLIGHT_LINE)
self._checkStyleOnLine.stateChanged[int].connect(
self._enable_check_inline)
vvbox.addWidget(self._checkStyleOnLine)
vvbox.addItem(QSpacerItem(0, 0,
QSizePolicy.Expanding, QSizePolicy.Expanding))
vboxg4.addLayout(vvbox)
# Container for tree widget and buttons
widget = QWidget()
hhbox = QHBoxLayout(widget)
hhbox.setContentsMargins(0, 0, 0, 0)
# Tree Widget with custom item delegate
# always adds uppercase text
self._listIgnoreViolations = QTreeWidget()
self._listIgnoreViolations.setObjectName("ignore_pep8")
self._listIgnoreViolations.setItemDelegate(ui_tools.CustomDelegate())
self._listIgnoreViolations.setMaximumHeight(80)
self._listIgnoreViolations.setHeaderLabel(
translations.TR_PREFERENCES_EDITOR_CONFIG_IGNORE_PEP8)
for ic in settings.IGNORE_PEP8_LIST:
self._listIgnoreViolations.addTopLevelItem(QTreeWidgetItem([ic]))
hhbox.addWidget(self._listIgnoreViolations)
box = QVBoxLayout()
box.setContentsMargins(0, 0, 0, 0)
btn_add = QPushButton(QIcon(":img/add_small"), '')
btn_add.setMaximumSize(26, 24)
btn_add.clicked.connect(self._add_code_pep8)
box.addWidget(btn_add)
btn_remove = QPushButton(QIcon(":img/delete_small"), '')
btn_remove.setMaximumSize(26, 24)
btn_remove.clicked.connect(self._remove_code_pep8)
box.addWidget(btn_remove)
box.addItem(QSpacerItem(0, 0,
QSizePolicy.Fixed, QSizePolicy.Expanding))
hhbox.addLayout(box)
vboxg4.addWidget(widget)
formFeatures.addWidget(group4)
# Show Python3 Migration, DocStrings and Spaces (highlighter)
vboxg5 = QVBoxLayout(group5)
vboxg5.setContentsMargins(5, 15, 5, 5)
self._showMigrationTips = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_SHOW_MIGRATION)
self._showMigrationTips.setChecked(settings.SHOW_MIGRATION_TIPS)
vboxg5.addWidget(self._showMigrationTips)
self._checkForDocstrings = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_CHECK_FOR_DOCSTRINGS)
self._checkForDocstrings.setChecked(settings.CHECK_FOR_DOCSTRINGS)
vboxg5.addWidget(self._checkForDocstrings)
self._checkShowSpaces = QCheckBox(
示例5: OTMainWindow
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setHeaderLabel [as 别名]
class OTMainWindow(QWidget):
def __init__(self, parent=None):
super(OTMainWindow, self).__init__(parent, Qt.Window)
self.setWindowTitle('OPC Python Tester')
self.layout = QVBoxLayout()
#
self.tree = QTreeWidget(self)
self.tree.setHeaderLabel('OPC server tree')
self.tree_root = QTreeWidgetItem()
self.tree_root.setText(0, 'not connected')
self.tree.addTopLevelItem(self.tree_root)
self.tree.itemDoubleClicked.connect(self.on_tree_item_double_clicked)
#
self.table = QTableWidget(self)
self.table.setRowCount(0)
self.table_column_labels = [
'item_id', 'value', 'type', 'access', 'quality', 'timestamp']
self.table.setColumnCount(len(self.table_column_labels))
self.table.setHorizontalHeaderLabels(self.table_column_labels)
self.table.horizontalHeader().setStretchLastSection(True)
#
self.splitter = QSplitter(Qt.Horizontal, self)
self.splitter.setChildrenCollapsible(False)
self.splitter.setHandleWidth(10)
self.layout.addWidget(self.splitter)
# final
self.splitter.addWidget(self.tree)
self.splitter.addWidget(self.table)
self.splitter.setSizes([150, 300])
self.setLayout(self.layout)
# self.opcsrv = None
self.cur_server_info = {}
self.cur_comp_name = ''
self.watched_itemids = []
self.ssdialog = ServerSelectDialog(self)
ssel_ret = self.ssdialog.exec_()
if ssel_ret == QDialog.Accepted:
self.do_connect(self.ssdialog.selected_server, self.ssdialog.selected_comp_name)
else:
print('Connection cancelled')
self.timer = QTimer(self)
self.timer.timeout.connect(self.on_timer_timeout)
self.timer.start(1000) # every 1 second
def do_connect(self, srv_info: dict, comp_name: str):
print('Connecting to "{0}" ({1}) on comp: {2}...'.format(
srv_info['desc'], srv_info['guid'], comp_name))
self.opcsrv = opc_helper.opc_connect(srv_info['guid'], comp_name)
if self.opcsrv is None:
return
self.cur_comp_name = comp_name
self.cur_server_info = srv_info
print(self.opcsrv.get_status())
self.fill_tree()
def fill_tree(self):
self.tree.clear()
if self.opcsrv is None:
return
self.tree_root = QTreeWidgetItem(self.tree)
self.tree_root.setChildIndicatorPolicy(QTreeWidgetItem.DontShowIndicatorWhenChildless)
root_title = '{0}'.format(self.cur_server_info['desc'])
if self.cur_comp_name != '':
root_title = '{0} ({1})'.format(self.cur_server_info['desc'], self.cur_comp_name)
self.tree_root.setText(0, root_title)
self.tree.addTopLevelItem(self.tree_root)
server_tree = self.opcsrv.browse(flat=False)
#
for oitem in server_tree:
self.fill_item(oitem, self.tree_root)
def fill_item(self, item: dict, parent: QTreeWidgetItem):
tree_item = QTreeWidgetItem()
tree_item.setChildIndicatorPolicy(QTreeWidgetItem.DontShowIndicatorWhenChildless)
tree_item.setText(0, item['name'])
if item['children'] is None:
# set userdata = item_id only if this IS a LEAF node
tree_item.setData(0, Qt.UserRole, item['item_id']) # column, role, data
parent.addChild(tree_item)
# recurse into children
if item['children'] is not None:
for oitem in item['children']:
self.fill_item(oitem, tree_item)
@pyqtSlot(QTreeWidgetItem, int)
def on_tree_item_double_clicked(self, item: QTreeWidgetItem, column: int):
# void itemDoubleClicked(QTreeWidgetItem * item, int column)
# virtual QVariant data(int column, int role) const
item_data = item.data(0, Qt.UserRole)
if item_data is None:
return
item_id = str(item_data)
print('Double click on [{0}]'.format(item_id))
self.opcsrv.get_item(item_id)
if item_id not in self.watched_itemids:
self.watched_itemids.append(item_id)
#.........这里部分代码省略.........