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
Related
I have following problem - if i select cell and then select empty space in tableWidget i can't again edit cell, i have to select another cell and again previous to be able edit it.
In vide i'm trying to edit second cell, but can't do this.
https://youtu.be/ibAFT1OkeHQ
I read about QTableWidget properties but did't find anything useful.
Found solution
QObject::connect(ui->tableWidgetData, &QTableWidget::clicked,
ui->tableWidgetData, QOverload<const QModelIndex&>::of(&QTableWidget::edit));
And on QTableWidget choose selection mode NoSelection.
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.
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);
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.
I require a button/link within a table row of a QTableView. This is to open a dialog to allow that row to be edited more efficiently.
After hours of looking on the web I am yet to find a decent example.
I am aware that this is likely to be done using a QItemDelegate, but I am unsure how to have a functional widget within the row without forcing the item into edit mode first.
Any help would be greatly appreciated.
You can use setIndexWidget for that, see the Qt documentation for more information.
As an example, to embed a push button in the first column of the second row (untested code):
tableView->setIndexWidget(tableView->model()->index(2, 1), new QPushButton);
You could emulate the functionality of a link by underlining the clickable text, then capturing the cell click via the cellClicked(row, col) signal and check that col == editColumn. Then row would correspond to which item you are editing.
For example,
Data Name | Value 1 | Value 2 | Edit
connect (tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(editSlot(int, int)));
...
void ClassName::editSlot(int row, int col){
if (col == 3) {
doWork(row);
}
}