Questions tagged [qstandarditem]

The QStandardItem class provides an item for use with the QStandardItemModel class. Items usually contain text, icons, or checkboxes.

The QStandardItem class provides an item for use with the QStandardItemModel class. Items usually contain text, icons, or checkboxes.

Each item can have its own background brush which is set with the setBackground() function. The current background brush can be found with background(). The text label for each item can be rendered with its own font and brush. These are specified with the setFont() and setForeground() functions, and read with font() and foreground().

By default, items are enabled, editable, selectable, checkable, and can be used both as the source of a drag and drop operation and as a drop target. Each item's flags can be changed by calling setFlags(). Checkable items can be checked and unchecked with the setCheckState() function. The corresponding checkState() function indicates whether the item is currently checked.

Documentation for Qt 4.8 and for Qt 5.

67 questions
42
votes
1 answer

Adding a right-click menu for specific items in QTreeView

I'm writing a Qt desktop application in c++ with Qt Creator. I declared in my main window a treeView, and a compatible model. Now, I would like to have a right-click menu for the tree item. Not for all of the items, but for a part of them, for…
user1835297
  • 1,059
  • 2
  • 12
  • 24
14
votes
1 answer

How to iterate through a QStandardItemModel completely?

I have a QStandardItemModel, which I display in q QTreeView. Works fine. To highlight relevant rows I want to highlight some of them: Therefore I have a QStringList with the names of the QStandItem* s to be highlighted. QStringList…
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103
10
votes
1 answer

PyQT -- How can you make a QTreeview uneditable but also selectable?

I just switched from wxPython to PyQT and I am having some trouble with the QTreeview. I have a QTreeview that will display data categorized into sections that are expandable, but the data in this TreeView should not be editable, but I need to be…
4
votes
1 answer

QStandardItem missing __hash__ method

I found when converting some Python2/Qt4 code to Python3/Qt5, that apparently QStandardItem can no longer be used as a dict key in as it doesn't have __hash__ implemented, and therefore is not considered immutable anymore. Those two snippets show…
4
votes
2 answers

Qt itemChanged signal with QTreeView model works only on first level items

I don't know if I do something wrong in my qt code. I just need that itemChanged signal is emitted every time when item data changed. I use following code to make the model: QStandardItemModel* model = new QStandardItemModel; QStandardItem…
Meteo ir3
  • 449
  • 8
  • 21
4
votes
0 answers

adding row to the QStandardItemModel

I have QStandardItemModel and the data are represented as lists model = QtGui.QStandardItemModel(0, 2) myrow = [1, "B"] My first solution how to add the row was with function setData() model.insertRow(0) for i,item in enumerate(myrow): …
Meloun
  • 13,601
  • 17
  • 64
  • 93
4
votes
1 answer

Remove item from QStandardItem in loop

I want to remove specific children from item, my parent item is const, ie. I can't replace it with a different parent item, I have to work on the one I have. Children items have multiple levels of children by itself. I've tried this but it doesn't…
user4442454
4
votes
0 answers

Qt Drag/Drop behavior for custom item type

I have a custom item class derived from QStandardItem being using in a QTableView (the model is just QStandardItemModel). I would like to be able to drag items from this view and drop the text (Qt::DisplayRole) onto a separate QTableWidget. Using…
ryan0270
  • 1,135
  • 11
  • 33
3
votes
3 answers

Finding / removing a row from a QStandardItemModel by item data

I have a QStandardItemModel with a single column (represents a list). Each item in the list has a unique integer ID stored as the QStandardItem's data (via QStandardItem::setData which I guess is into Qt::UserRole+1 by default). Given one of these…
Jason C
  • 38,729
  • 14
  • 126
  • 182
3
votes
1 answer

Deallocation of items in QStandardItemModel

When QStandardItemModel, which is allocated on the stack, gets destroyed, what happens with objects to which pointers in the model are pointing at (e.g. item/item2 pointer as in the following example): QStandardItem* item = new…
mspehar
  • 527
  • 1
  • 6
  • 19
3
votes
1 answer

PyQt5: Setting data for a QStandardItem

If I construct a QStandardItem like so: item = QtGui.QStandardItem('Item Name') When this item is added to a QStandardItemModel model and is viewed in a QTreeView I get a cell that says Item Name. However, when I construct one like: item =…
NineTails
  • 550
  • 4
  • 24
3
votes
3 answers

How to access childWidgets in a QTreeView using QModelIndex?

I'm working on an application using the Qt library (version 4.8). I have a QTreeView with a QStandardItemModel. My widget looks like that: Item1 subitem11 subitem12 Item2 subitem21 subitem22 Item3 subitem31 subitem32 Here is how I add the items to…
user2738748
  • 1,106
  • 2
  • 19
  • 36
3
votes
1 answer

Get Item from QStandardItemModel for QTableView

I have a QTreeView in which each node represents a data object. I managed to pack a pointer to this data objects into a QVariant so that I know which is selected in the Tree. I can access the nodes by the currentIndex() function. The root of the…
3
votes
1 answer

How to strikeout text of QStandardItem in Qt/PyQt?

I have a QStandardItemModel in PySide, and want to strikeout text on certain rows (it is a to do list application and when a task is done, I want to strike through the text). Given a QStandardItem that displays fine, based on the documentation I try…
eric
  • 7,142
  • 12
  • 72
  • 138
3
votes
2 answers

How to "Print Out" the data of a QStandardItem

Is there a way to print the data of a QstandardItem out, say I have; QList testQList; QString yay = "!Yay"; QStandardItem *item = new QStandardItem(yay); testQList.append(item); qDebug() << testQList; I just get the memory addres,…
user4217633
  • 71
  • 3
  • 10
1
2 3 4 5