本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.setExpandsOnDoubleClick方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.setExpandsOnDoubleClick方法的具体用法?Python QTreeWidget.setExpandsOnDoubleClick怎么用?Python QTreeWidget.setExpandsOnDoubleClick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.setExpandsOnDoubleClick方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TorrentPreferencesDialog
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setExpandsOnDoubleClick [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)
#.........这里部分代码省略.........
示例2: ImperiumWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setExpandsOnDoubleClick [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
#.........这里部分代码省略.........
示例3: Ui_Ucics
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setExpandsOnDoubleClick [as 别名]
#.........这里部分代码省略.........
# ------------添加到布局
toolLayout.addWidget(self.qzoneButton, 0, Qt.AlignLeft)
toolLayout.addWidget(self.skinButton, 1, Qt.AlignLeft)
# --------添加到布局
headInfoLayout.addWidget(self.nameLabel)
headInfoLayout.addWidget(self.moodEdit)
headInfoLayout.addWidget(self.toolWidget)
# ----天气
self.weatherLabel = QLabel(self.headWidget)
self.weatherLabel.setMinimumWidth(60)
self.weatherLabel.setMaximumWidth(60)
self.weatherLabel.setCursor(QCursor(Qt.PointingHandCursor))
self.weatherLabel.setObjectName("weatherLabel")
# ----添加到布局中
headLayout.addWidget(self.headLabel, 0, Qt.AlignLeft)
headLayout.addWidget(self.headInfoWidget, 0, Qt.AlignCenter)
headLayout.addWidget(self.weatherLabel, 0, Qt.AlignRight)
# 搜索输入框
self.searchEdit = LineEdit(self.bgWidget)
self.searchEdit.setFrame(False)
# self.searchEdit.setClearButtonEnabled(True)
self.searchEdit.setObjectName("searchEdit")
# tab
self.tabWidget = QTabWidget(self.bgWidget)
self.tabWidget.setUsesScrollButtons(False) # 取消两个切换按钮
self.tabWidget.setDocumentMode(True) # 取消边框
self.tabWidget.setObjectName("tabWidget")
# --分组
self.tabGroup = QWidget(self.tabWidget)
self.tabGroup.setObjectName("tabGroup")
# ----分组布局
groupVerticalLayout = QVBoxLayout(self.tabGroup)
groupVerticalLayout.setSpacing(0)
groupVerticalLayout.setContentsMargins(0, 0, 0, 0)
groupVerticalLayout.setObjectName("groupVerticalLayout")
# ------分组list控件
self.groupTreeWidget = QTreeWidget(self.tabGroup)
self.groupTreeWidget.setFrameShape(QFrame.NoFrame)
self.groupTreeWidget.setFrameStyle(QFrame.NoFrame)
self.groupTreeWidget.setLineWidth(0)
self.groupTreeWidget.setIndentation(0)
self.groupTreeWidget.setRootIsDecorated(False)
self.groupTreeWidget.setExpandsOnDoubleClick(False)
self.groupTreeWidget.header().setVisible(False)
self.groupTreeWidget.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.groupTreeWidget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.groupTreeWidget.setObjectName("groupTreeWidget")
# ----添加到布局
groupVerticalLayout.addWidget(self.groupTreeWidget)
# --历史
self.tabHistory = QWidget(self.tabWidget)
self.tabHistory.setObjectName("tabHistory")
# ----历史布局
historyVerticalLayout = QVBoxLayout(self.tabHistory)
historyVerticalLayout.setSpacing(0)
historyVerticalLayout.setContentsMargins(0, 0, 0, 0)
historyVerticalLayout.setObjectName("historyVerticalLayout")
# ------历史list控件
self.historyTreeWidget = QTreeWidget(self.tabHistory)
self.historyTreeWidget.setFrameShape(QFrame.NoFrame)
self.historyTreeWidget.setFrameStyle(QFrame.NoFrame)
self.historyTreeWidget.setLineWidth(0)
self.historyTreeWidget.setIndentation(0)
self.historyTreeWidget.setRootIsDecorated(False)
self.historyTreeWidget.setExpandsOnDoubleClick(False)
self.historyTreeWidget.header().setVisible(False)
self.historyTreeWidget.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.historyTreeWidget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.historyTreeWidget.setObjectName("historyTreeWidget")
# ----添加到布局
historyVerticalLayout.addWidget(self.historyTreeWidget)
# 添加到tab中
self.tabWidget.addTab(self.tabGroup, "")
self.tabWidget.addTab(self.tabHistory, "")
# 整体布局
verticalLayout = QVBoxLayout(self.bgWidget)
verticalLayout.setSpacing(0)
verticalLayout.setContentsMargins(0, 0, 0, 0)
verticalLayout.setObjectName("verticalLayout")
verticalLayout.addWidget(self.topWidget)
verticalLayout.addWidget(self.headWidget)
verticalLayout.addWidget(self.searchEdit)
verticalLayout.addWidget(self.tabWidget)
# bg
layout = QVBoxLayout(Ucics)
layout.setSpacing(0)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.bgWidget)
# 初始化一些设置
_translate = QCoreApplication.translate
Ucics.setWindowTitle(_translate("Ucics", "UCICS"))
self.tabWidget.setCurrentIndex(0)
self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.tabGroup), _translate("tabGroup", "分组"))
self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.tabHistory), _translate("tabHistory", "历史"))
QMetaObject.connectSlotsByName(Ucics)