setting selection for multiple items in a QTreeView - pyqt4

So I've been using :
treeView.setCurrentIndex( index )
to set the active item in my treeView. But if I have an array of item indices that I would like to select, how do I add to my currently selected item?
Thx!

A QTreeView doesn't have as many bundled methods as a QTreeWidget, so you have to drop down to the other components for some functionality. In this case, you might want to use the SelectionModel.
selModel = treeView.selectionModel()
for idx in indexList:
selModel.select(idx, selModel.Select)

Related

Dynamic select box/multiselect box based on other field in pimcore

In the class definition, I have two select boxes, first select box has 5 items if I select any item from the first select box, the value of the second select box should get change. I am using pimcore v6.3.1.
Try to make custom combobox(Select BOX) using EXT JS and onChange Event Get The data for another combobox then save those datas in database.
You can use pimcore dynamic select types: https://pimcore.com/docs/6.x/Development_Documentation/Objects/Object_Classes/Data_Types/Dynamic_Select_Types.html

Force user to select only one value from filter spotfire

Is it possible to force the user to select only one value from a filter ?
For a radio button filter as below, is it possible to remove the buttons all & none and make sure that only one Choice is selected ?
you cannot change the existing filter features or functionality without developing a custom extension for a new filter control.
that said, you can certainly emulate a filter using what's called a Property Control and a Data Limiting Expression. for single selection, you're stuck with either a Dropdown control or a Listbox (single select) control.
you would need to...
create a Text Area Visualization on the page somewhere
insert a Listbox or Dropdown Property Control into the Text Area Visualization
create a Document Property with the same data type as your filter column and associate it to the Property Control. you can set this to Unique Values in Column or write in your own Fixed values.
open the Properties dialog on the visualization you'd like to filter and navigate to the Data page
scroll down to Limit Data Using Expression and use an expression like [MyFilterColumn] = "${MyDocumentProperty}" (quotes are required for string values; if numeric then omit quotes)
Please add this CSS in the HTML page of the spotifre to remove all and none
.ColumnFilter .sf-element-filter-item:last-of-type { display:none; }
.ColumnFilter .sf-element-filter-item:first-of-type { display:none; }
Another way to force the users to select one option is to add a Show/Hide in the visualization like this: Hide if UniqueCount([Field]) is greater than 1

QListWidget deselection and multiple selection

i'm just searching in the docu and can not find the solution for the following two problems with QListWidget:
a) i would like to deselect (deactivate) items in the QListWidget from the software (i mean code)
b) i use multiple selection: setSelectionMode(QAbstractItemView.MultiSelection)
I would like to pre-select more than one item from the code. If i use
setCurrentRow() i can only select on item (it toggles the selected item). How can i do multiple selections?
Your help is very welcome
Both of those could be done with the setSelected method of QListWidgetItems.
# select item
listWidget.item(row).setSelected(True)
# deselect item
listWidget.item(row).setSelected(False)
You can do this for multiple items and as long as you have MultipleSelection enabled, it would select/deselect those items.

Native PyQt function returning selected QTreeWidgetItems in order of selection?

I have a QTreeWidget which uses the QAbstractItemView.ExtendedSelection property, allowing users to shift click and control click items.
I'd like to preform actions on these items based on the order in which they are selected-- I can think of ways to design my own systems to determine the selection order, but is there a native function/property that will return a list of items sorted via selection order?
Thank you for your advice!
The underlying selection model naturally preserves in the order in which items are selected. So you don't really need to do anything special - just iterate over them like this:
for item in treewidget.selectedItems():
print item.text(0)

DrawItem in listbox (VC++)

When we will use DrawItem for a listbox?
Normally, if the listbox is ownerdraw, we will use DrawItem. What are the other senarios we use drawitem?
To elaborate on Rashmi Pandit; A ListBox with override DrawItem can also be used to 'visualize' objects. In a project I'm working on, a ListBox is used to display rows from a database. Each row / item is visualized using formatted Strings, Icons etc.
Overriding DrawItem (and MeasureItem!) is ideal for this purpose. Of course, the internal structure has to be tweaked a bit (the standard Items property cannot be used for objects), but it is certainly worthwhile.
Message WM_DRAWITEM is sent only to owner-drawn List boxes.
You can use DrawItem when you want to override the default implementation and custom the way a listbox is drawn. For e.g. in the list there might be some item which should is the default item and you would want it to be highlighted so that the user knows it is the default item.
Here's an eg for a combo in C#: Higlighting a particular item in a combo box

Resources