interactivly resizable rows in QListWidget - c++

In a QTableWidget I can configure the rows to be resizable by the user on run time by setting the verticalHeader's resizeMode to Interactive like this:
table.verticalHeader().setResizeMode(QtGui.QHeaderView.Interactive)
How would I configure a similar behavior for QListWidget? Unfortunately the QListWidget resizeMode does not have an Interactive item and I haven't found anything similar.
The best would be to configure it for the whole list but when it's possible for single rows/items that would be ok, too.

As doc said:
This view does not display horizontal or vertical headers; to display
a list of items with a horizontal header, use QTreeView instead.
So you should use QTreeView (or QTreeWidget) with one column and maybe with specific style.
Another approach. There are no header, so you can provide some instrument (dialog window, slider or something else) where user will be able to change row height, to change row height you should just use setData() and set QSize() to Qt::SizeHintRole. For example:
ui->listWidget->model()->setData(ui->listWidget->currentIndex(),
QSize(40,40),Qt::SizeHintRole);

Related

Winforms controlling controls

I couldn't think of a coherent search term for my problem so please forgive me if this has been asked before.
I have 24 combo boxes sitting on a panel control, displayed in 4 rows of 6.
After the user defines the value for each combo and hits the "go" button, I add all combo boxes to list so I can use the values in another section of my program.
The problem is that the order the comboboxes are added to the list is messed up, compared to their visual layout on the panel, and I would like to define the order. Currently, it adds the 9th combobox to the list first then the 20th, 2nd, 16th etc etc.
I tried TabIndex but that didnt work.
Before I manually rename and relabel all of the boxes, any other suggestions will be gratefully received.
The controls of your form exist in Controls collection of the container controls, for example when you add a Panel and a Button to a Form and two ComboBox to the Panel, then:
Form.Controls contains button1 and panel1
Panel.Controls contains comboBox1 and comboBox2
Controls are added to the Controls collection, with the same order that you add them to designer. Open designer.cs, look at the end of InitializeComponent to see the order.
You can also see/change the order using Document Outline window.
That said, now it should be obvious that panel1.Controls.OfType<ComboBox>() returns combo boxes with the same order that you see in Document Outline (or based on their z-index, and it doesn't have anything to do with their x/y placements).
You may want to order them based on TabIndex, or any other property that you like:
panel1.Controls.OfType<ComboBox>().OrderBy(x=>x.TabIndex)
Note
In general, if you are going to use those values for a search, instead of relying on the order of values, a much better idea is creating a SearchModel class which has a few properties, the set those properties to the selected value of the corresponding combo box (manually or using databinding) then pass the search model to the other classes.

How can I assign different selection modes?

I have default QTableView.
I want to get following selection behaviour:
If we selecting cells, selection will work like if we accepted SelectionMode::ContiguousSelection
If we selecting rows/column by clicking on QHeaderView section, selection will work like we accepted SelectionMode::ExtendedSelection, but deselect all cells, if any were selected.
I tried set SelectionMode to headers in QTableView constructor, but it doesn't work.
Question is how can I do it properly?
Okay, got it.
All I had to do is just make custom selection model and handle everything in there. But I had to change SelectionMode::ContiguousSelectionto SelectionMode::ExtendedSelection in my view to get meaningful indexes in my selection model.

Change label of QComboxBox without using lineEdit

Currently I want to implement a widget to allow user to enable/disbale all provided options of a QSet. So i took a combobox and added selectable items. So far so good, but how I can change text displayed in combobox? Currently all my items have just ItemIsUserCheckable and ItemIsEnabled as enabled flags (ItemIsSelectable is not enabled), so text of ComboBox is always text of first item. Instead I want as text "Flag1, Flag 3, Flag6" if there multiple flags and user enabled Flag 1, 3 and 6. But setCurrentText and setEditText requiring setEditable(true) or an custom lineEdit. But using an lineEdit is changing appearance. So is there another way?
I had a similar problem a while back, I ended up 'solving' it by adding an extra item to my model that was first in the list and always set as the current item. I then updated it's text to say 'Select items...' or 'X item(s) selected' as appropriate.

QTableWidget - combobox delegate how do I allow different options per cell

Aloha
I have a QTableWidget with two columns that are currently using a ComboboxDelegate (my subclass of QItemDelegate) to present options to the user. I'd like the choice in the first column to effect the options available in the second, for the current row only.
E.g have a list of cars in the first column, and in the second a list of colours which are available for that car. Other rows to have different cars selected and thus different colour choices available.
From what I can see, I can only set an item delegate per row or column, so I can't see how to change the options in the second column's delegate without affecting all the other rows.
Is this possible? I'd really like to avoid going to a full view/model separation as I have quite a bit of code looking at this QTableWidget already (and I'm under time pressure)
Well for those interested; I went back to my pre-delegate approach, which was to use QTableWidget::setItemWidget() to provide a combobox widget for each cell.
I subclassed qcombobox to take a reference to the table, and connected the combobox CurrentIndexChanged with a slot to update the table data.
(setting a widget in a cell does not affect the tablewidget data unless you do this).
Using a full combobox like this is more expensive than an itemdelegate, but my tables are very small so I can get away with it. The rendering of the combobox is not as nice as the delegate (the combobox is visible all the time instead of only during editing in the delegate's case), but with time I'm sure I can improve on this.

Follow layout except content

Right now I have where the tablewidget and calendar resizes as the window is expanded/contracted. But as you can see my table (2 columns, x rows) also follow the layout. How do I break out of this? What I want is the calendar and table widget to resize as the form expands and the two columns filling up the entire widget. Something like this:
You have to set size policies for these widgets with setSizePolicy() method - here is docs . And chose behavior you desire from this enum
For example, if you want tablewidget to take all available space:
tablewidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);