qtreewidget

QTreeWidget editItem fails with “edit: editing failed”

余生长醉 提交于 2019-12-05 15:22:01
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 (item->text(column).toInt() < 1) { QMessageBox::critical(this, "Error", QString("Node ID ") + item->text

How to get the number of items of a QTreeWidget

拜拜、爱过 提交于 2019-12-05 14:56:16
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 You can write a recursive function that will run over the hierarchy and count all visible items. For example: int treeCount

Invoking context menu in QTreeWidget

有些话、适合烂在心里 提交于 2019-12-05 14:42:26
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? 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 like this: class ItemDelegate: public QItemDelegate { public: ItemDelegate(ContextMenuHandler *const

How to automatically sort a QTreeWidget column?

你说的曾经没有我的故事 提交于 2019-12-05 14:31:12
问题 I'm using a QTreeWidget to display some simple items. I've set the list sortable by .setSortingEnabled(true) calling. In this way, the list is sorted only when the user press the title column, and not automatically whenever new item is inserted. Is there a way to force the automatic sorting in a specified column without calling .sortItems(column) at every item insertion? If it's possible, I would highlight the whole sorted column. 回答1: To do this, use QTreeView::setSortingEnabled() and

Multiple Selection QTreeWidget

此生再无相见时 提交于 2019-12-05 14:05:16
问题 Does anyone know if its possible to select multiple items on a QTreeWidget and how to go about enabling the multiple selection? All the items I want to be selectable are top level QTreeWidgetItems and all their children are set to be disabled (i.e QTreeWidgetItem.setDisabled(True) ) 回答1: It is, you'll want to call setSelectionMode during init to enable QAbstractItemView::MultiSelection. QTreeView/QTreeWidget inherit QAbstractItemView, so it is available. Then to disable the items, just hook

QTreeView or QTreeWidget

旧街凉风 提交于 2019-12-05 03:45:19
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 else. Are my worries rational and should I go to the model/view structure, or can I easily get going

Is it possible to sort numbers in a QTreeWidget column?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 05:49:51
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? 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)const { int column = treeWidget()->sortColumn(); return text(column).toLower() < other.text(column).toLower();

Multiple Selection QTreeWidget

佐手、 提交于 2019-12-04 01:05:56
Does anyone know if its possible to select multiple items on a QTreeWidget and how to go about enabling the multiple selection? All the items I want to be selectable are top level QTreeWidgetItems and all their children are set to be disabled (i.e QTreeWidgetItem.setDisabled(True) ) Mike Ramirez It is, you'll want to call setSelectionMode during init to enable QAbstractItemView::MultiSelection. QTreeView/QTreeWidget inherit QAbstractItemView, so it is available. Then to disable the items, just hook on to QTreeWidgets.itemSelectionChanged() signal. I think below will help: youQTreeWidget

How to automatically sort a QTreeWidget column?

对着背影说爱祢 提交于 2019-12-04 00:28:37
I'm using a QTreeWidget to display some simple items. I've set the list sortable by .setSortingEnabled(true) calling. In this way, the list is sorted only when the user press the title column, and not automatically whenever new item is inserted. Is there a way to force the automatic sorting in a specified column without calling .sortItems(column) at every item insertion? If it's possible, I would highlight the whole sorted column. Bille To do this, use QTreeView::setSortingEnabled() and QTreeView::sortByColumn . Just remember to turn this on /after/ you initially populate the widget, and turn

How to resize columns in QTreeWidget to the minimum space required

十年热恋 提交于 2019-12-04 00:26:42
问题 I am a student programmer and I am using Qt to build a GUI interface for work. I have a QTreeWidget that has a total of 8 Columns. The input that needs to be entered into each one of these columns is fairly small. In that regard, I was trying to find a way to re-size all of the columns to the least amount of space required. much like the action that is performed when you click on the dividers. I have looked over several websites and the Qt documentation and haven't found a solution. After