variable column number in qtreewidget - c++

I want to have a qtreewidget with 1 column header but its children have more columns, I tried below code but I want to hide subsidies header too.
treeView = new QTreeView;
treeView->setModel(completer->model());
treeView->header()->hide();
treeView->expandAll();
thanks

You should reimplement QHeaderView for your needs, because QTreeView uses number of columns for root items.

Related

How to completely disable selection for qtableview (for all cells)?

I want my table to be not selectable, so that only check boxes or radio buttons could be selected, but not the cell itself. Now I have:
How can I fix this?
Solutions for QTableWidget can help too.
QTableView *test = new QTableView();
test->setSelectionMode(QAbstractItemView::NoSelection);
gives the wanted result.

interactivly resizable rows in QListWidget

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);

How to set row height of QTableView?

I have QTableView and QAbstractTableModel. I require rows to have height equal to 24. I know the only way to do this is by calling QTableView::setRowHeight. Since the model is dynamic it may be added new rows, but I don't want to call setRowHeight each time new row is added.
How can I configure QTableView such that it uses the same height for new added rows or can a model be sent the height of rows?
For Qt versions < 5
QHeaderView *verticalHeader = myTableView->verticalHeader();
verticalHeader->setResizeMode(QHeaderView::Fixed);
verticalHeader->setDefaultSectionSize(24);
For Qt versions >= 5 use
QHeaderView *verticalHeader = myTableView->verticalHeader();
verticalHeader->setSectionResizeMode(QHeaderView::Fixed);
verticalHeader->setDefaultSectionSize(24);
If that function doesn't apply to vertical headers, you likely will have to call setRowHeight() every time you add a new row.

QTableWidget change selection mode

When clicking on QTableWidget cell, it selects only the cell. How to configure tablewidget, so that when click on a cell , the whole row will be selected which contains the cell?
It can be done using signal,slots. I'm curious is there standard way doing it?
Simply use setSelectionBehavior
QTableView * tmp = new QTableView();
tmp->setSelectionBehavior(QAbstractItemView::SelectRows);
http://doc.qt.io/qt-5/qabstractitemview.html#SelectionBehavior-enum

QTreeView - remove expandable look on some elements

I'd like to remove expandable attribute on some elements in QTreeView (populated with model inherited from QFileSystemModel). I can easily collapse this elements right after they are expanded, but they will be still visible in QTreeView as expandable.
How can I show them as unexpandable ones?
I believe you just have to override the default behaviour in the rowCount of your QFileSystemModel derived class to return zero rows for when that QModelIndex of the row you don't want to be expandable.
See http://qt-project.org/doc/qt-5.0/model-view-programming.html#models particularly the Tree Model diagram.