Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
window.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4/*
5 window.cpp
6
7 A minimal subclass of QTableView with slots to allow the selection model
8 to be monitored.
9*/
10
11#include <QAbstractItemModel>
12#include <QItemSelection>
13#include <QItemSelectionModel>
14#include <QStatusBar>
15
16#include "model.h"
17#include "window.h"
18
20 : QMainWindow(parent)
21{
22 setWindowTitle("Selected items in a table model");
23
24 model = new TableModel(8, 4, this);
25
26 table = new QTableView(this);
27 table->setModel(model);
28
29 selectionModel = table->selectionModel();
34
35 statusBar();
36 setCentralWidget(table);
37}
38
41 const QItemSelection &deselected)
42{
43 QModelIndexList items = selected.indexes();
44
45 for (const QModelIndex &index : std::as_const(items)) {
46 QString text = QString("(%1,%2)").arg(index.row()).arg(index.column());
47 model->setData(index, text);
49 }
51
53 items = deselected.indexes();
54
55 for (const QModelIndex &index : std::as_const(items)) {
56 model->setData(index, QString());
57}
59
61void MainWindow::changeCurrent(const QModelIndex &current,
62 const QModelIndex &previous)
63{
64 statusBar()->showMessage(
65 tr("Moved from (%1,%2) to (%3,%4)")
66 .arg(previous.row()).arg(previous.column())
67 .arg(current.row()).arg(current.column()));
68}
void changeCurrent(const QModelIndex &current, const QModelIndex &previous)
void updateSelection(const QItemSelection &selected, const QItemSelection &deselected)
[0]
Definition window.cpp:40
virtual Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This signal is emitted whenever the selection changes.
void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted whenever the current item changes.
\inmodule QtCore
Q_CORE_EXPORT QModelIndexList indexes() const
Returns a list of model indexes that correspond to the selected items.
The QMainWindow class provides a main application window.
Definition qmainwindow.h:25
\inmodule QtCore
constexpr int row() const noexcept
Returns the row this model index refers to.
constexpr int column() const noexcept
Returns the column this model index refers to.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition qstring.cpp:8870
The QTableView class provides a default model/view implementation of a table view.
Definition qtableview.h:18
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
[0]
Definition model.h:12
QString text
GLuint index
[2]
GLenum GLenum GLsizei void * table
SSL_CTX int void * arg
#define tr(X)
QSqlQueryModel * model
[16]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QList< QTreeWidgetItem * > items
statusBar() -> addWidget(new MyReadWriteIndication)
[0]