qtreewidget

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

QTreeWidget for File Tree and Sub-folders

倖福魔咒の 提交于 2019-12-24 12:50:07
问题 So, what i'm using is a QTreeWidget to make a File-Tree. I can easily create the files, and folders. But the issue comes when we talk about sub-folders. For example: Folder1 Folder1/SubFolder1 Folder1/SubFolder1/SubFolder2 How do i exactly create the sub-folders? Here's my code to make the folders: void Tree::addFolder(const QString &folderName) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, folderName); // Sets the text. m_projectItem->addChild(item); // Adds it to the

How do I check if a checkbox is checked or unchecked? (In QTreeWidget)

℡╲_俬逩灬. 提交于 2019-12-24 12:05:36
问题 I have written the code below: from PyQt4 import QtCore, QtGui import sys class window(QtGui.QMainWindow): def __init__(self, parent=None): super(window, self).__init__(parent) self.TreeWidget = QtGui.QTreeWidget() self.TreeWidget.setColumnCount(1) item1 = QtGui.QTreeWidgetItem(["Item 1"]) item1.setCheckState(0, QtCore.Qt.Checked) item2 = QtGui.QTreeWidgetItem(["Item 2"]) item2.setCheckState(0, QtCore.Qt.Unchecked) item3 = QtGui.QTreeWidgetItem(["Item 3"]) item3.setCheckState(0, QtCore.Qt

HowTo draw QTreeWidgetItem with different style?

淺唱寂寞╮ 提交于 2019-12-24 09:27:57
问题 Here is the main problem : I'm using QTreeWidget class as a main tree, which must show me this tree structure: [Today] [Row1] [Row2] [SubRow21] [SubRow22] [Row3] [Yesterday] [Row4] [SubRow41] [etc] With Qt Designer I have set this style sheet code: QTreeWidget#treeWidget::item { height: 24px; border: none; background-position: bottom left; background-image: url(:/backgrounds/images/backgrounds/row_back.png); } QTreeWidget#treeWidget::item:selected { color: #000000; background-position: bottom

Set column width for QTreeWidget

一世执手 提交于 2019-12-22 05:04:52
问题 Is there any way to set column width for QTreeWidget from code? I want to chage default width of first column. I'm using PySide. 回答1: QHeaderView::resizeSection() should do the trick, in C++ it would look like this: myTreeWidget->headerView()->resizeSection(0 /*column index*/, 100 /*width*/); 回答2: For people looking for a C++ Qt solution (tested with 5.12): // Important to call setMinimumSectionSize because resizeSection wont work if your width is less than the minimum treeWidget->header()-

How can I save the file in TreeView as a json file again?

会有一股神秘感。 提交于 2019-12-20 06:49:23
问题 I can show and edit a json file in QTreeWidget form. How can I save this edited json file again on desktop. my goal is to create a json editor that we can edit import json from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt class ViewTree(QTreeWidget): def __init__(self, value): super().__init__() def fill_item(item, value): def new_item(parent, text, val=None): child = QTreeWidgetItem([text]) child.setFlags(child.flags() | Qt.ItemIsEditable) fill_item(child, val) parent.addChild(child)

PyQT QTreeWidget iterating

懵懂的女人 提交于 2019-12-19 09:56:38
问题 I have two columns in a QTreeWidget , one column represents a list of urls and the second represents results . I have loaded the list of urls in first column and now I want to iterate this list and during the iteration, change the text in the second column. How to achieve this? 回答1: You can call QTreeWidget.invisibleRootItem() to receive the root item, and then use the QTreeWidgetItem API to iterate through the items. Example: root = self.treeWidget.invisibleRootItem() child_count = root

How to create delegate for QTreeWidget?

邮差的信 提交于 2019-12-17 23:08:18
问题 Here is what I'm trying to do (all parents and children must have a close button on the right, in the future, only the hovered item will be able to show the **close ** button): My delegate code: class CloseButton : public QItemDelegate { Q_OBJECT public: CloseButton( QObject* parent = 0 ) : QItemDelegate( parent ) {}; QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const { if ( index.column() == 1 ) { QToolButton* button = new QToolButton

one type of file format in QTreeView

本秂侑毒 提交于 2019-12-12 21:28:52
问题 Is it possible to set only one file format visible to the user? I'm searching it in documentation, but I can't find it... If not, which other widget you are suggesting to use? 回答1: I assume you're using a QTreeView with a QFileSystemModel. If not, I'd suggest doing so. QTreeWidget is not as flexible. QFileSystemModel has a method called setNameFilters that should do what you want. To use it, do something like this: QStringList filters; filters.append("*.cc"); // whatever filters you want

Qt model/view vs standard widget

戏子无情 提交于 2019-12-12 14:46:55
问题 I am currently reading model/view tutorial from Qt, but I am still not sure if I should use model/view or widget for my Qt program : I need to do a logger application that will monitor all information in a simulation environment. Basic scenario might be : User 1 say something to virtual entity B (logger application get what user 1 said and show it in table view or list view) Virtual entity B reply something to user 1 (logger application get what user 1 said and add it in table view or list