本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.setColumnWidth方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.setColumnWidth方法的具体用法?Python QTreeWidget.setColumnWidth怎么用?Python QTreeWidget.setColumnWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.setColumnWidth方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_variable_table
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnWidth [as 别名]
def get_variable_table(self, context):
context_key = context.replace(' ', '-').lower()
if context_key in self.variable_tables:
table = self.variable_tables[context_key]
else:
table = QTreeWidget()
table.setColumnCount(3)
table.setHeaderLabels(['Name', 'Type', 'Value'])
table.setColumnWidth(0, 250)
table.setColumnWidth(1, 150)
self.variable_tables[context_key] = table
if context == 'Locals':
self.insertTab(0, table, context)
else:
self.addTab(table, context)
table.itemDoubleClicked.connect(
self.handle_variable_double_clicked
)
self.setCurrentIndex(0)
return table
示例2: InfoDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnWidth [as 别名]
class InfoDialog(QDialog):
def __init__(self, parent, info, title):
super().__init__(parent)
self.setWindowTitle('Media Info - ' + title)
self.setWindowModality(QtCore.Qt.ApplicationModal)
self.setMinimumSize(500, 250)
self.resize(500, 250)
self.vLayout = QVBoxLayout(self)
self.infoTree = QTreeWidget(self)
self.infoTree.setColumnCount(2)
self.infoTree.setHeaderLabels(['Scope', 'Value'])
self.infoTree.setAlternatingRowColors(True)
self.infoTree.setSelectionMode(QAbstractItemView.NoSelection)
self.infoTree.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.vLayout.addWidget(self.infoTree)
self.__generate_widgets(info)
self.infoTree.setColumnWidth(0, 150)
self.buttonBox = QDialogButtonBox(self)
self.buttonBox.setStandardButtons(QDialogButtonBox.Close)
self.vLayout.addWidget(self.buttonBox)
self.buttonBox.rejected.connect(self.close)
def __generate_widgets(self, info, parent=None):
for key in sorted(info.keys()):
if(isinstance(info[key], dict)):
widget = QTreeWidgetItem([key])
self.__generate_widgets(info[key], widget)
else:
widget = QTreeWidgetItem([key, info[key]])
if(parent):
parent.addChild(widget)
else:
self.infoTree.addTopLevelItem(widget)
示例3: BookmarksWindow
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnWidth [as 别名]
class BookmarksWindow(QDialog):
"""
A simple UI for showing bookmarks and navigating to them.
FIXME: For now, this window is tied to a particular lane.
If your project has more than one lane, then each one
will have it's own bookmark window, which is kinda dumb.
"""
def __init__(self, parent, topLevelOperatorView):
super(BookmarksWindow, self).__init__(parent)
self.setWindowTitle("Bookmarks")
self.topLevelOperatorView = topLevelOperatorView
self.bookmark_tree = QTreeWidget(self)
self.bookmark_tree.setHeaderLabels( ["Location", "Notes"] )
self.bookmark_tree.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Preferred )
self.bookmark_tree.setColumnWidth(0, 200)
self.bookmark_tree.setColumnWidth(1, 300)
self.note_edit = QLineEdit(self)
self.add_bookmark_button = QPushButton("Add Bookmark", self, clicked=self.add_bookmark)
geometry = self.geometry()
geometry.setSize( QSize(520, 520) )
self.setGeometry(geometry)
layout = QVBoxLayout()
layout.addWidget(self.bookmark_tree)
layout.addWidget(self.note_edit)
layout.addWidget(self.add_bookmark_button)
self.setLayout(layout)
self._load_bookmarks()
self.bookmark_tree.setContextMenuPolicy( Qt.CustomContextMenu )
self.bookmark_tree.customContextMenuRequested.connect( self.showContextMenu )
self.bookmark_tree.itemDoubleClicked.connect(self._handle_doubleclick)
def _handle_doubleclick(self, item, col):
"""
Navigate to the bookmark
"""
data = item.data(0, Qt.UserRole).toPyObject()
if data is None:
return
(coord, notes) = data
axes = self.topLevelOperatorView.InputImages.meta.getAxisKeys()
axes = axes[:-1] # drop channel
axes = sorted(axes)
assert len(axes) == len(coord)
tagged_coord = dict(list(zip(axes, coord)))
tagged_location = OrderedDict(list(zip('txyzc', (0,0,0,0,0))))
tagged_location.update(tagged_coord)
t = list(tagged_location.values())[0]
coord3d = list(tagged_location.values())[1:4]
self.parent().editor.posModel.time = t
self.parent().editor.navCtrl.panSlicingViews( coord3d, [0,1,2] )
self.parent().editor.posModel.slicingPos = coord3d
def showContextMenu(self, pos):
item = self.bookmark_tree.itemAt(pos)
data = item.data(0, Qt.UserRole).toPyObject()
if data is None:
return
def delete_bookmark():
(coord, notes) = data
bookmarks = list(self.topLevelOperatorView.Bookmarks.value)
i = bookmarks.index((coord, notes))
bookmarks.pop(i)
self.topLevelOperatorView.Bookmarks.setValue(bookmarks)
self._load_bookmarks()
menu = QMenu(parent=self)
menu.addAction( QAction("Delete", menu, triggered=delete_bookmark) )
globalPos = self.bookmark_tree.viewport().mapToGlobal( pos )
menu.exec_( globalPos )
#selection = menu.exec_( globalPos )
#if selection is removeLanesAction:
# self.removeLanesRequested.emit( self._selectedLanes )
def add_bookmark(self):
coord_txyzc = self.parent().editor.posModel.slicingPos5D
tagged_coord_txyzc = dict( list(zip('txyzc', coord_txyzc)) )
axes = self.topLevelOperatorView.InputImages.meta.getAxisKeys()
axes = axes[:-1] # drop channel
axes = sorted(axes)
coord = tuple(tagged_coord_txyzc[c] for c in axes)
notes = str(self.note_edit.text())
bookmarks = list(self.topLevelOperatorView.Bookmarks.value)
bookmarks.append((coord, notes))
self.topLevelOperatorView.Bookmarks.setValue(bookmarks)
self._load_bookmarks()
def _load_bookmarks(self):
self.bookmark_tree.clear()
#.........这里部分代码省略.........
示例4: CustomWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnWidth [as 别名]
class CustomWidget(QMainWindow):
def __init__(self):
"""
Constructor
"""
QMainWindow.__init__(self)
self.name = "Custom widget"
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
# TODO: This is ugly, improve it
self.icon_path = JConfig().icons_path
self._createLayout()
def _createGui(self):
"""
Subclasses must override this
depending on the elements they want to add
self._createOutputTree(),
self._createOutputTable(),
self._createOutputWindow() and add them to
the corresponding layouts.
"""
raise NotImplementedError
def _createToolBar(self, name):
"""
Subclasses need to define the
specific Actions
"""
self.toolbar = self.addToolBar(name)
self.toolbar.setMovable(False)
def _createLayout(self):
"""
This creates the basic layout:
Buttons & Outputs
"""
# Layouts (This is a common disposition)
main_layout = QVBoxLayout()
self.button_layout = QHBoxLayout()
output_layout = QVBoxLayout()
# You will need to create your buttons
# and add them to your layout like this:
# self.button_layout.addWidget(button_1)
# Output Layout Inner (QSplitter)
# Add as many widgets as you please
# They will be ordered vertically and
# be resizable by the user
# self.splitter.addWidget(self.table_label)
# self.splitter.addWidget(...)
self.splitter = QSplitter(QtCore.Qt.Vertical)
# Nested layouts
main_layout.addLayout(self.button_layout)
output_layout.addWidget(self.splitter)
main_layout.addLayout(output_layout)
self.central_widget.setLayout(main_layout)
def _createOutputWindow(self):
"""
Some binary analysis commands will output to this.
"""
self.output_label = QLabel('Output')
self.output_window = QTextEdit()
self.output_window.setFontPointSize(10)
self.output_window.setReadOnly(True)
# Save it for later use
self.output_window.original_textcolor = self.output_window.textColor()
def _createOutputTable(self):
"""
A vanilla QTableWidget. Callbacks modify
its properties, like number of columns, etc.
"""
self.table_label = QLabel('Table Output')
self.table = QTableWidget()
self.table.setColumnCount(3)
self.table.setColumnWidth(0, 100)
self.table.setColumnWidth(1, 300)
self.table.setColumnWidth(2, 300)
self.table.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
# Connect signals to slots
self.table.customContextMenuRequested.connect(self._tablePopup)
self.table.horizontalHeader().sectionDoubleClicked.connect(
self._tableHeaderDoubleClicked)
self.table.cellDoubleClicked.connect(self._tableCellDoubleClicked)
def _createOutputTree(self):
"""
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnWidth [as 别名]
def __init__(self, *args, **kwargs):
super(ShortcutManagerDlg, self).__init__(*args, **kwargs)
self.setWindowTitle("Shortcut Preferences")
self.setMinimumWidth(500)
self.setMinimumHeight(500)
mgr = ShortcutManager() # Singleton
scrollWidget = QWidget(parent=self)
tempLayout = QVBoxLayout(scrollWidget)
scrollWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
treeWidget = QTreeWidget(parent=scrollWidget)
treeWidget.setHeaderLabels(["Action", "Shortcut"])
treeWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
treeWidget.setColumnWidth(0, 300)
treeWidget.setColumnWidth(1, 50)
action_descriptions = mgr.get_all_action_descriptions()
target_keyseqs = mgr.get_keyseq_reversemap()
# Create a LineEdit for each shortcut,
# and keep track of them in a dict
shortcutEdits = collections.OrderedDict()
for group, targets in list(action_descriptions.items()):
groupItem = QTreeWidgetItem(treeWidget, [group])
for (name, description) in targets:
edit = QLineEdit(target_keyseqs[(group, name)])
shortcutEdits[(group, name)] = edit
item = QTreeWidgetItem(groupItem, [description])
item.setText(0, description)
treeWidget.setItemWidget(item, 1, edit)
tempLayout.addWidget(treeWidget)
# Add ok and cancel buttons
buttonLayout = QHBoxLayout()
cancelButton = QPushButton("Cancel")
cancelButton.clicked.connect(self.reject)
okButton = QPushButton("OK")
okButton.clicked.connect(self.accept)
okButton.setDefault(True)
buttonLayout.addSpacerItem(QSpacerItem(10, 0, QSizePolicy.Expanding))
buttonLayout.addWidget(cancelButton)
buttonLayout.addWidget(okButton)
tempLayout.addLayout(buttonLayout)
scroll = QScrollArea(parent=self)
scroll.setWidget(scrollWidget)
scroll.setWidgetResizable(True)
scroll.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
dlgLayout = QVBoxLayout()
dlgLayout.addWidget(scroll)
self.setLayout(dlgLayout)
# Show the window
result = self.exec_()
# Did the user hit 'cancel'?
if result != QDialog.Accepted:
return
for (group, name), edit in list(shortcutEdits.items()):
oldKey = target_keyseqs[(group, name)]
newKey = str(edit.text())
if oldKey.lower() != newKey.lower() and newKey != "":
mgr.change_keyseq(group, name, oldKey, newKey)
mgr.store_to_preferences()
示例6: ImperiumWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnWidth [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
#.........这里部分代码省略.........
示例7: TorrentPreferencesDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnWidth [as 别名]
class TorrentPreferencesDialog(QDialog):
dataReady = pyqtSignal(dict)
def __init__(self, parent, torrent_info):
super().__init__(parent)
self.torrentInfo = torrent_info
self.setUp()
def setUp(self):
self.setWindowTitle("Torrent settings")
parentRect = self.parentWidget().geometry()
self.resize(parentRect.width() * 0.75, parentRect.height() * 0.9)
self.setMinimumSize(self.size())
# Create the dialog layout
self.layout = QVBoxLayout(self)
# Set up the destination folder selector
self.setUpDialogHeader()
# Set up the file lister for the torrent file
self.setUpFileLister()
# Set up the whole torrent priority combo box and buttons
self.setUpDialogFooter()
def setUpDialogHeader(self):
headerLayout = QGridLayout()
self.destinationFolder = paths.writableLocation(paths.DownloadLocation)
torrentName = self.torrentInfo.name()
# Show the torrent name row
nameLabel = QLabel("Torrent name:", self)
headerLayout.addWidget(nameLabel, 0, 0)
nameEdit = QLineEdit(torrentName, self)
nameEdit.setReadOnly(True)
headerLayout.addWidget(nameEdit, 0, 1)
# Show the destination folder row
dirLabel = QLabel("Destination folder:", self)
headerLayout.addWidget(dirLabel, 1, 0)
self.textField = QLineEdit(self.destinationFolder, self)
self.textField.setReadOnly(True)
headerLayout.addWidget(self.textField, 1, 1)
button = QPushButton("Browse", self)
button.clicked.connect(self.selectFolder)
headerLayout.addWidget(button, 1, 2)
self.layout.addLayout(headerLayout)
def selectFolder(self):
newDir = str(QFileDialog.getExistingDirectory(self,
"Select Directory"))
if newDir:
self.textField.setText(newDir)
self.destinationFolder = newDir
def setUpFileLister(self):
self.files = [(f.path, f.size) for f in self.torrentInfo.files()]
self.treeView = QTreeWidget(self)
self.treeView.setColumnCount(3)
self.treeView.setColumnWidth(0, 350)
self.treeView.setColumnWidth(1, 80)
self.treeView.setHeaderLabels(["Name", "size", "Priority"])
self.treeView.setExpandsOnDoubleClick(False)
if len(self.files) == 1:
tree = file_tree.FileTree(self.files[0][0], self.files[0][1])
else:
tree = file_tree.FileTree(self.files[0][0].split('/')[0], 0)
for f in self.files:
tree.add_file(f[0], f[1])
rootItem = TreeNodeItem(tree.get_root(), self.treeView)
self.treeView.addTopLevelItem(rootItem)
self.treeView.expandAll()
self.treeView.itemClicked.connect(self.rowClicked)
self.layout.addWidget(self.treeView)
def rowClicked(self, item, column):
if item.checkState(0) == Qt.PartiallyChecked:
item.setCheckState(0, Qt.Checked)
if column == 2:
priorityChanges = {'Normal': 'High',
'High': 'Low',
'Low': 'Normal',
'Mixed': 'Normal'}
newPriority = priorityChanges[item.text(2)]
self.changeTextOfAllChildren(item, 2, newPriority)
self.reprioritize(item)
def changeTextOfAllChildren(self, item, column, text):
item.setText(column, text)
for i in range(0, item.childCount()):
self.changeTextOfAllChildren(item.child(i), column, text)
#.........这里部分代码省略.........
示例8: InspectorWindow
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnWidth [as 别名]
#.........这里部分代码省略.........
rightSideBearing = str(int(self._glyph.rightMargin))
if self._glyph.markColor is not None:
markColor = QColor.fromRgbF(
*tuple(self._glyph.markColor))
self.nameEdit.setText(name)
self.unicodesEdit.setText(unicodes)
self.widthEdit.setText(width)
self.leftSideBearingEdit.setText(leftSideBearing)
self.rightSideBearingEdit.setText(rightSideBearing)
self.markColorWidget.setColor(markColor)
def _updateLayerAttributes(self, notification=None):
self.layerSetWidget.clear()
if self._font is None:
return
layerSet = self._font.layers
if layerSet is None:
return
for layer in layerSet:
item = QTreeWidgetItem(self.layerSetWidget)
item.setFlags(item.flags() | Qt.ItemIsEditable)
item.setText(0, layer.name)
widget = ColorVignette(self)
color = layer.color
if color is not None:
color = QColor.fromRgbF(*tuple(color))
widget.setColor(color)
widget.setMargins(2, 2, 2, 2)
widget.setMayClearColor(False)
widget.colorChanged.connect(self.writeLayerColor)
widget.setProperty("layer", layer)
self.layerSetWidget.setItemWidget(item, 1, widget)
self.layerSetWidget.setColumnWidth(1, 100)
# ---------
# Callbacks
# ---------
# glyph attributes
def writeGlyphName(self):
if self._glyph is None:
return
self._glyph.name = self.nameEdit.text()
def writeUnicodes(self):
if self._glyph is None:
return
unicodes = self.unicodesEdit.text().split(" ")
if len(unicodes) == 1 and unicodes[0] == "":
self._glyph.unicodes = []
else:
self._glyph.unicodes = [int(uni, 16) for uni in unicodes]
def writeWidth(self):
if self._glyph is None:
return
self._glyph.width = int(self.widthEdit.text())
def writeLeftSideBearing(self):
if self._glyph is None:
return
self._glyph.leftMargin = int(self.leftSideBearingEdit.text())
def writeRightSideBearing(self):