天道酬勤,学无止境

qtreewidget

为 QTreeWidget 设置列宽(Set column width for QTreeWidget)

问题 有没有办法从代码中为 QTreeWidget 设置列宽? 我想改变第一列的默认宽度。 我正在使用 PySide。 回答1 QHeaderView::resizeSection() 应该可以解决这个问题,在 C++ 中它看起来像这样: myTreeWidget->headerView()->resizeSection(0 /*column index*/, 100 /*width*/); 回答2 对于寻找 C++ Qt 解决方案的人(用 5.12 测试): // Important to call setMinimumSectionSize because resizeSection wont work if your width is less than the minimum treeWidget->header()->setMinimumSectionSize(25); treeWidget->header()->resizeSection(1 /*column index*/, 25 /*width*/); // You might also need to use this if you want to limit the size of your last column: treeWidget->header()->setStretchLastSection

2021-07-11 05:46:28    分类:技术分享    qt   pyqt   pyside   qtreewidget

如何删除 QTreeWidgetItem(How to delete QTreeWidgetItem)

问题 几个网页都说QTreeWidgetItem可以通过delete或者QTreeWidget.clear来删除。 但是我下面的代码示例似乎没有这样做。 我做错了什么吗? #!/usr/bin/python import sys from PySide.QtGui import QApplication, QWidget, QTreeWidget, QTreeWidgetItem #from PyQt4.QtGui import QApplication, QWidget, QTreeWidget, QTreeWidgetItem # Result was the same with `PySide` import time class TreeWidgetItemChild(QTreeWidgetItem): def __init__(self): super(TreeWidgetItemChild, self).__init__() print 'TreeWidgetItemChild init' def __del__(self): print 'TreeWidgetItemChild del' def test_QTree_clear_children(): tree = QTreeWidget() tree.setHeaderLabel('funksoul') i =

2021-07-10 14:02:19    分类:技术分享    python   qt   pyside   qtreewidget   qtreewidgetitem

QTreeWidget editItem 失败并显示“编辑:编辑失败”(QTreeWidget editItem fails with “edit: editing failed”)

问题 我有一个QTreeWidgetItem添加到QTreeWidget : QTreeWidgetItem* item = new QTreeWidgetItem(ui->trwPairs); item->setFlags(item->flags() | Qt::ItemIsEditable); 如果该项目被编辑,我想对新值进行一些检查: Pairs::Pairs(QWidget *parent) : QWidget(parent), ui(new Ui::Pairs) { ui->setupUi(this); connect(this->ui->trwPairs, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(Validate(QTreeWidgetItem*,int))); } void Pairs::Validate(QTreeWidgetItem* item, int column) { if (item->text(column).toInt() < 1) { QMessageBox::critical(this, "Error", QString("Node ID ") + item->text(column) + " is invalid."); ui->trwPairs->editItem(item

2021-07-10 06:49:44    分类:技术分享    c++   qt   qwidget   qtreewidget

QTreeWidget (Applying Styles for items)

I have a tree widget and there are three levels in the tree as follows Example Tree ============================ LEVEL1 LEVEL2 LEVEL2 LEVEL3 LEVEL3 LEVEL2 LEVEL2 LEVEL1 I want to apply different styles for items, depending their levels so that I can style, LEVEL1, LEVEL2 & LEVEL3 differently. I can do this with a two level tree. Please help. I want to achieve this at CSS level (without touching the code) I went through following documenation. I guess distinguishing between LEVEL1 & LEVEL2 is the hard part. http://doc.qt.digia.com/main-snapshot/stylesheet-examples.html#customizing-qtreeview

2021-07-03 07:06:13    分类:问答    qt   qtreeview   qtreewidget   qstyle

Tracking checked items in QTreeWidget when loading in new set of data

I have a QTreeWidget in my gui in which the contents will be cleared whenever it loads in a different set of data and I am trying to tracked what has been checked as User loads in different data set. Initially, I thought of tracking it using derive_tree_items method that I created in which it contains the QTreeWidgetItem object, however as soon as I tried to load in a new set of data, the objects that I stored will be lost as they are deleted (expected).. Currently at a lost what is a better way to 'track' these checkable items? (I may also need to populate them into QMenu + QAction, hence the

2021-06-29 03:09:53    分类:问答    python   pyqt   pyqt4   qtreewidget

Determine visible size of a QTreeWidget column

I need to determine the VISIBLE width of a column within a QTreeWidget. I'll explain my problem with a small example. A QTreeWidget defines three columns with the fixed width of col 1=200 px, col 2=100 px and col 3=300 px. The widget itself has a ( resizeable ) width of 350. The width of all colums ( 200 + 100 + 300 = 600 ) exeeds the with of the widget, so a scrollbar is shown. For some special calculation I need to know the visible width of the third column: Case A would be quite easy, I just need to subtract: widget - col 1 - col2 = 350 - 200 - 100 = 50. But what should I do in case B? To

2021-06-28 14:41:00    分类:问答    c++   qt   qtreewidget

PyQt4 Qtreewidget - get hierarchy text if child checkbox is checked

What I am currently trying to do is take a populated tree (qtreewidget) that has checkboxes at the bottom child level, and return the text of the path to the child if the box is checked. The reason I want to do this, is if a child is checked, it will then change a value in a key in a dictionary. (The "raw" dictionary the tree was created from). Here's a visual example of what I mean: From user input and server directory crawling, we have populated a tree that looks something like this: (Only the lowest level child items have checkboxes.) And sorry for the horrible tree diagram!! Hopefully it

2021-06-26 19:21:06    分类:问答    python   pyqt   pyqt4   qtreewidget   qcheckbox

how to make a particular column in QTreeWidget integer/Float, such that the user can't enter any alphabets or symbols instead of integers/Floats?

I am making a GUI in PyQt5 which uses QTreeWidget. I want a particular column to be integer only column. The user shouldn't be able to enter any non integer item in it. I saw some methods using QVariant but it doesn't seem to fullfill my requirement. Here is what I found! .But this seems to me like setting the data from the back-end not from the user side. from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(478, 320) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget

2021-06-26 07:12:22    分类:问答    python   pyqt   pyqt5   qtreewidget

Showing filesystem in QTreeWidget

I have a simple Question. I want to show my filesystem in a QTreeWidget just like an common file explorer. How can i achieve that? I guess searching through all files and add them manual is not the approach to chose, right?

2021-06-26 04:28:50    分类:问答    c++   qt   qtreewidget

How to connect QTreeWidget and QStackedWidget in PyQt4?

I'm sorry but just a beginner of Python. I just want to change index of QStackedWidget by the item click of QTreeWidget. I searched for the tutorials of SIGNAL and SLOT online, but just cannot solve the problem. The parameters in QTreeWidget signal and QStackedWidget slot are not fitted. self.connect(qtree, QtCore.SIGNAL("itemClicked(QTreeWidgetItem*,int)"), stack, QtCore.SLOT("setCurrentIndex(int)")) And I tried this: qtree.itemClicked.connect(stack.setCurrentIndex) It just showed the error: TypeError: setCurrentIndex(self, int): argument 1 has unexpected type 'QTreeWidgetItem' I think there

2021-06-25 18:01:27    分类:问答    python   pyqt   pyqt4   qtreewidget   qstackedwidget