qtreewidgetitem

Iteration of a QTreeWidget

限于喜欢 提交于 2021-02-11 06:20:32
问题 I have a QTreeWidget that I am using to represent a breakdown structure of data. Basically I plan on using my QTreeWidget in a way to track the population of certain demographics in cities. For example: Males 9,000 - New York 5,000 - D.C. 4,000 Females 10,000 - Nashville 3,000 - San Diego 7,000 Obviously this data is just for example. A few problems I am having with implementing this. I can't figure out how to iterate over the tree. So that every so often I can check if the data has changed.

Iteration of a QTreeWidget

…衆ロ難τιáo~ 提交于 2021-02-11 06:20:18
问题 I have a QTreeWidget that I am using to represent a breakdown structure of data. Basically I plan on using my QTreeWidget in a way to track the population of certain demographics in cities. For example: Males 9,000 - New York 5,000 - D.C. 4,000 Females 10,000 - Nashville 3,000 - San Diego 7,000 Obviously this data is just for example. A few problems I am having with implementing this. I can't figure out how to iterate over the tree. So that every so often I can check if the data has changed.

Is it possible to sort numbers in a QTreeWidget column?

大城市里の小女人 提交于 2020-01-12 21:21:35
问题 I have a QTreeWidget with a column filled with some numbers, how can I sort them? If I use setSortingEnabled(true); I can sort correctly only strings, so my column is sorted: 1 10 100 2 20 200 but this is not the thing I want! Suggestions? 回答1: You can sort overriding the < operator and changing sort condiction like this. class TreeWidgetItem : public QTreeWidgetItem { public: TreeWidgetItem(QTreeWidget* parent):QTreeWidgetItem(parent){} private: bool operator<(const QTreeWidgetItem &other

How to delete QTreeWidgetItem

混江龙づ霸主 提交于 2020-01-01 08:52:53
问题 Several webpages say that QTreeWidgetItem can be deleted by deleting or QTreeWidget.clear ing. But my code sample below doesn't seem to do so. Am I doing anything wrong? #!/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)

Making only one column of a QTreeWidgetItem editable

主宰稳场 提交于 2019-12-28 06:17:14
问题 I have a QTreeWidgetItem with two columns of data, is there any way to make only the second column editable? When I do the following: QTreeWidgetItem* item = new QTreeWidgetItem(); item->setFlags(item->flags() | Qt::ItemIsEditable); all columns become editable. 回答1: Looks like you will have to forgo using QTreeWidget and QTreeWidgetItem and go with QTreeView and QAbstractItemModel . The "Widget" classes are convenience classes that are concrete implementations of the more abstract but more

Using QTreeWidgetItems setData to store a QStackedWidget or QVariant

寵の児 提交于 2019-12-24 19:33:51
问题 I am trying to make a QTreeWidget such that each row contains a series of comboboxes. Depending on how the user interacts with the comboboxes I would like certain comboboxes to becomes line edits and some to become buttons. It was suggested here that a QStackedWidget would serve my needs and its done a pretty good job except now I need a way to alter the QStackedWidget that is next to the one that contains the combobox sending me an indexChanged signal. (Basically I want to change the

PyQt validity check on QTreeWidgetItem

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 05:34:44
问题 I'm building a QTreeWidget where I'm implementing adding new item and renaming functionality. I'd like to check the validity of the new name given by user, including: the name can only contain a list of valid characters. This is achieved already by adding a QRegExpValidator to a subclassed QItemDelegate , and assigning the new delegate to the QTreeWidget . the name can't conflict with its siblings. This I don't know now to achieve. Here is my current attempt: import sys from PyQt5.QtWidgets

Remove space from QLabel in a QTreeWidget

冷暖自知 提交于 2019-12-10 21:28:03
问题 I've added QLabel widgets to my QTreeWidget to work around the word wrapping issue in QTreeWidget. (see how to word wrap a QTreeWidgetItem). The QLabel widgets appear to have spacing around the text which for some reason disappears when the text wraps. It also does not show up when the Label text is blank. I tried setting setContentsMargin(0,0,0,0) on the QLabel but that didn't work. I also tried setStyleSheet("border: 0px; margin: 0px; padding: 0px;") which also didn't help. Screenshot: You

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

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