How use QTableView customized complicated table? - qt

I want use QTableView to draw a complex table, the table style like bellow.
Table style
The header contain "C" char and row contain "Data" char
The problem is I don't know how to use pyqt to draw table like this, can someone have any ideas ?

Related

How to make QHeaderView editable like data in cells?

I'm using a QAbstractTableModel to edit a panda dataframe. Editing the contents of the table was easy but i can't find the way to rename columns and rows inplace(like the rest of the data in the table). How I can do that?

QT: QTableView read cell content

I'm writing a small program with QT creator (QT 5.2.1) under Windows 7 (32 bit) and I'm having problems reading the informations stored in a TableView. My application has 3 elements, a TableView to store text data, a TextBrowser to show info and a buttom.
I modified the TableView properties: when the user selects with the mouse a cell, the full row is selected and multiple row selection is not allowed.
The user select a row and when the buttom is pressed, I would like to read the content of a specific TableView cell and show it in a TextBrowser. In particular, I would like to know the row index of the selected row and read the content of the cell with that row index and a specific column index (example 2).
The pseudo-code is this:
void my_program::on_pushButton_clicked()
{
ui->textBrowser->append("button pressed");
QItemSelectionModel *select = ui->tableView->selectionModel();
int index_row = select->selectedRows();
int index_column = 2;
char cell_data[30] = ??[index_row][index_column]
ui->textBrowser->append(cell_data);
}
The main problem is that select->selectedRows() returns a QModelIndex that is a collection of indexs and I do not know how to convert it to int (since multiple selection are not allowed, it should have only one element).
I would be glad if someone can suggest me a way to proceed.
Thanks
Francesco
edit:
Hi Bogdan, thanks a lot!! I succeed to read the cell content by using
ui->textBrowser->append(ui->tableView->model()->data(ui->tableView->model()->index(2,5)).toString());
this give me the content of the cell in position 2,5.
not sure if this is the best way or not but it works !!.
Can you be a bit more precise about how to iterate the QModeIndexList ? thanks :)
selectedRows() returns QModelIndexList, thus you need to iterate over it and call QModelIndex::data() to get stored data.

Qt: QTableView how to add a row?

I have got a QTableView with data in it. What is the simplest way to add a row?
Thanks!
As you use som YourModel to show it in YourTableView (QTableView) should do like this:
YourModel->insertRow(YourModel->rowCount(QModelIndex()));
// paste some data to new row
update of model causes update of View
QTableView is model based if you don't know what model is then I suggest you read here.
Use QTableWidget instead is much easier for a beginner and you can add a row just like this
ui->tableWidget->insertRow(0);

How to line up data in a UITableView cell?

I have this UITableView (http://imgur.com/3YQzm) that I want to list 3 textfields on each row. The info is stored on a SQLite d/b. The first row I need for titles.
How can I list the info in each row so it looks "nice" (i.e. lined up in columns)? Do I need a custom cell for this?
As far I know, you have to put the labels in the specific locations, so you have to define the coordenates for a nice look. I don't know if you are using a xib file for the cell, but, for this case, is better to use it. In the xib will be easy to set the correct location for your labels.

Edit all selected items into one editor

Using QTableView I would like to be able to select multiple cells and change all selected cells at once. How I can do it?
I'm not sure exactly what you mean by "changing" the selected cells (content, formatting, something else?) but I think QTableView::selectedIndexes() (or QTableView::selectionModel() if you need more power) is going to help out. You can loop through the returned indexes and update your underlying model.
If you are using a QSortFilterProxyModel you will have to use the QSortFilterProxyModel::mapFromSource() and related methods to map from the selected cells on your table view to the actual model indexes.

Resources