qtreewidget

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?

我的未来我决定 提交于 2019-12-10 11:31:46
问题 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(

PyQt4 Qtreewidget - get hierarchy text if child checkbox is checked

被刻印的时光 ゝ 提交于 2019-12-10 11:29:17
问题 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

How to get the number of items of a QTreeWidget

拈花ヽ惹草 提交于 2019-12-10 09:11:46
问题 I have created a QTreeWidget, I'm trying to list all the items displayed. I do not want to go inside the items if the item have child but not expanded. It's really getting the number of Items I can see in the tree. I have tried : for( int i = 0; i < MyTreeWidget->topLevelItemCount(); ++i ) { QTreeWidgetItem *item = MyTreeWidget->topLevelItem(i); ... but this is giving me only the topLevelItem and I want all I can see. In the example, I should be able to count 14 items 回答1: You can write a

Invoking context menu in QTreeWidget

前提是你 提交于 2019-12-10 08:45:56
问题 I would like to popup a menu, when user clicks on an object in QTreeWidgetItem. I though about catching signal contextMenuRequested from QWidget and then retrieving index from the view using itemAt. But this doesn't seem very pretty. Is there any easier way to be able to call a menu on an item inside a view? 回答1: Write your own custom ItemDelegate and handle the click event in QAbstractItemDelegate::editorEvent . You can retreive the data in the cell from the QModelIndex. In C++ it would look

Multiple Columns in PyQt4 (potentially using QTreeWidget)

浪尽此生 提交于 2019-12-09 06:44:52
问题 I'm trying to get QTreeWidget working exactly similar to this one. In python! I don't care about multiple tabs but about multiple columns. This is what I've got so far. I don't know how to have more than one header though. self.pointListBox = QtGui.QTreeWidget() x=QtGui.QTreeWidgetItem() x.setText(0,str(coords[0])) y=QtGui.QTreeWidgetItem() y.setText(0,str(coords[1])) Qname=QtGui.QTreeWidgetItem() Qname.setText(0,new_point_name) self.pointListBox.setHeaderItem(Qname) parent = QtGui

QTreeWidget reordering child items by dragging

妖精的绣舞 提交于 2019-12-08 20:23:24
问题 I have a QTreeWidget which displays a single root node and one level of child nodes only. I need to permit the re-ordering of the child nodes. They must never be re-parented. This is how I enable the dragging of items in the QTreeWidget : ui->levelElements->setSelectionMode(QAbstractItemView::SingleSelection); ui->levelElements->setDragEnabled(true); ui->levelElements->viewport()->setAcceptDrops(true); ui->levelElements->setDropIndicatorShown(true); ui->levelElements->setDragDropMode

QTreeWidget (Applying Styles for items)

大兔子大兔子 提交于 2019-12-08 09:08:39
问题 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

QTreeWidget editItem fails with “edit: editing failed”

岁酱吖の 提交于 2019-12-07 08:41:14
问题 I have a QTreeWidgetItem added to a QTreeWidget : QTreeWidgetItem* item = new QTreeWidgetItem(ui->trwPairs); item->setFlags(item->flags() | Qt::ItemIsEditable); If the item is edited, I want to do a few checks on the new value: 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

QTreeView or QTreeWidget

徘徊边缘 提交于 2019-12-06 23:49:02
问题 I want to implement in my program a tree with nested sub-levels, and I'm looking for which of those two kind(View/Widget) is best suited for my goal. I have a list of days with task that are either done/missed/failed, each task has a count of how many times it was done/missed/failed and lastly a score for that day. I want to display them like so: I made this example in QtCreator using a QTreeWidget, but I'm worried that it would be hard to modify the elements since they are stored somewhere

QTreeWidgetItem清空子节点

徘徊边缘 提交于 2019-12-06 06:44:48
下面列出,xxbs遇到的注意点儿: 1、 QTreeWidget::collapseAll(); //xxbs::先折叠所有根项。 如果某个根是展开的,先删除根的子项再折叠,展开的凸显状态角色无法清除。 2、 int itemChildrenCounts = QTreeWidgetItem::childCount(); while(itemChildrenCounts--) { QTreeWidgetItem * child = QTreeWidgetItem::child(itemChildrenCounts); //index从大到小区做删除处理 QTreeWidgetItem::removeChild(child); delete child; child = nullptr; } 3、 QTreeWidget::setCurrentItem(nullptr); //设置QTreeWidget的当前项为空 来源: https://www.cnblogs.com/azbane/p/11966343.html