qmodelindex

Show Last element in QListView

Deadly 提交于 2021-01-29 10:49:29
问题 It sounds trivial, but I could not find the function to show the last added element in a QListView. It works with a model // Create model model = new QStringListModel(this); // Make data QStringList List; // Populate our model model->setStringList(List); // Glue model and view together listView->setModel(model); Elements are added with void WidgetMessageList::addString(const QString & message) { if(model->insertRow(model->rowCount())) { QModelIndex index = model->index(model->rowCount() - 1,

Pass QModelIndex instead of QString when QCompleter highlighted

只谈情不闲聊 提交于 2020-01-17 00:34:46
问题 There is a QCompleter (set to QLineEdit) populated with QStandardItemModel. That model also populates the QTableView, I need to get the QModelIndex and select it in QTableView but it fails, it passes text instead of QModelIndex: completer.highlighted.connect(print_index) passes only the first index: completer.highlighted.connect(lambda : select_index(completer.currentIndex())) def select_index(index): table_view.setCurrentIndex(index) I read docs, but cannot understand what do I do wrong.

Create a QModelIndex from a Data Item

試著忘記壹切 提交于 2020-01-15 23:54:09
问题 I'm looking for a way to create a QModelIndex from a particular piece of data in my model. I can go from a QModelIndex to a data item via: CustomData *data = static_cast<CustomData *>(modelIndex.internalPointer()); But I'm looking for an inverse function to go from: QModelIndex *index = createIndex(data); // ?? I've implemented linkages between my data very similar to the simple tree model example (http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html). My view displays the

How to iterate through a QStandardItemModel completely?

こ雲淡風輕ζ 提交于 2020-01-14 09:32:12
问题 I have a QStandardItemModel, which I display in q QTreeView. Works fine. To highlight relevant rows I want to highlight some of them: Therefore I have a QStringList with the names of the QStandItem* s to be highlighted. QStringList namesToBeHighlighted = getNames(); QModelIndex in = myModel->index(0, 0); if ( in.isValid() ) { for (int curIndex = 0; curIndex < myModel->rowCount(in); ++curIndex) { QModelIndex si = myModel->index(curIndex, 0, in); QStandardItem *curItem = myModel->itemFromIndex

How to loop over QAbstractItemView indexes?

不问归期 提交于 2020-01-13 03:00:31
问题 I want to fire QAbstractItemView::doubleClicked slot programaticaly for an item that has specific text. I want to do this using QAbstractItemView class and not it's implementations if possible. This task boils down to looping over items and comparing strings. But I cannot find any method that would give me all QModelIndex es. The only method that gives any QModelIndex without parameters is QAbstractItemView::rootIndex . But when I look into QModelIndex docs, I again cannot see a way to access

Converting QModelIndex to QString

Deadly 提交于 2019-12-23 09:50:09
问题 Is there a way to convert QModelIndex to QString? The main goal behind this is that I want to work with the contents of dynamically generated QListView-Items. QFileSystemModel *foolist = new QFileSystemModel; foolist->setRootPath(QDir::rootPath()); foolistView->setModel(foolist); [...] QMessageBox bar; QString foolist_selectedtext = foolistView->selectionModel()->selectedIndexes(); bar.setText(foolist_selectedtext); bar.exec; Is this even the correct way to get the currently selected Item?

How to get list of visible QModelIndex in QAbstractItemView

旧城冷巷雨未停 提交于 2019-12-23 09:43:12
问题 Is there any way to get a list of currently visible items in QAbstractItemView ? And, if it possible, to receive any notifications about changing of this list. Upd: I'm asking exactly about QAbstractItemView or QTreeView with non-plain structure, not QTableView . Upd2: I'm implementing tree view model with checkboxes. I want next behavior (same for checking/uncheking): If one of checkbox is checked - then all childs must be checked If all child checkboxes are checked - then parent check box

Read and write to a file from a QTableView

时光总嘲笑我的痴心妄想 提交于 2019-12-05 03:56:36
问题 How can I read and write to a text file date enter to a QTableView? This is what I have but I would like to save the data when it is added to the table and of course be able to read it back when the application is reopened. Is there any tutorial I can refer to? MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); model = new QStandardItemModel(); model->setRowCount(0); ui->tableView->setModel(model); } MainWindow::~MainWindow() { delete ui

Read and write to a file from a QTableView

孤街浪徒 提交于 2019-12-03 22:17:20
How can I read and write to a text file date enter to a QTableView? This is what I have but I would like to save the data when it is added to the table and of course be able to read it back when the application is reopened. Is there any tutorial I can refer to? MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); model = new QStandardItemModel(); model->setRowCount(0); ui->tableView->setModel(model); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QStandardItem *userName = new QStandardItem(ui->lineEdit