Qt QTableView / QAbstractTableModel / QTextTable

Qt Widgets
Model/View Tutorial
Model/View Programming
Presenting SQL Data in a Table View

Example

Star Delegate Example
Spin Box Delegate Example

Documentation / Class

QTabWidget Class
QTextTable Class
QHeaderView Class (
QAbstractTableModel Class
QAbstractItemModel Class
enum Qt::ItemDataRole

Handling Selections in Item Views

when i use “QScreen *screen = QGuiApplication::primaryScreen()” ,i get nullpt

Merge cells

QTreeView merge some cells
How to merge two cells of a qtable row?

Column/Row resize

Columns auto-resize to size of QTableView

How to update QTableView on QAbstractTableModel Change
ModelView with QTableView and QItemDelegate
Using QTableView with a model
Creating QTextTable And Inserting Data
QtextTable draw your own boarders
How to change row height in QTextTable
How to disable selection highlighting in a QTableWidget
How to set row height of QTableView?
Disable selecting row or column by clicking the header in QTableWidget

Focus Rectangle / Border Selection

Hide the border of the selected cell in qtablewidget in pyqt? (WORKS!)
How to disable selection highlighting in a QTableWidget
how to change style on a selected row
QTableWidget. Disable selection completely.

Row Height / Column Width

How to set row height of QTableView?
QTableView column width

Hide Vertical Header

How to remove the vertical header in QStandardItemModel?

Hide Column

Qt hide column in QTableView

Add QWidget or custom Painting in TableView

Adding button to QTableview
Star Delegate Example
Designing Delegates

Alignment

Centering the text of a vertical header in a QTableView?

Header

How to change the header background color of a QTableView
How to change QTableWidget header color and selection color ?
QTableView/QTableWidget grid stylesheet – grid line width

Update Model

The model emits signals to indicate changes. For example, dataChanged() is emitted whenever items of data made available by the model are changed. Changes to the headers supplied by the model cause headerDataChanged() to be emitted. If the structure of the underlying data changes, the model can emit layoutChanged() to indicate to any attached views that they should redisplay any items shown, taking the new structure into account.

How to modify the data in the model and update the view when new data is received from external?
How to update a QStringListModel
New in Qt 5.11: improvements to the model/view APIs (part 1)
How to set non-selectable default text on QComboBox?
QComboBox – Select no entry
ComboBox model change does not update graphical appearance every time
The ModelView Architecture

Source

#0  PatientModel::setData () at ../DatabaseSelect/src/business/PatientModel.cpp:188
#1  QAbstractItemModel::setItemData () at itemmodels/qabstractitemmodel.cpp:1912
#2  QComboBox::insertItem () at widgets/qcombobox.cpp:2315
#3  QComboBox::insertItem () at ../../../Qt/5.12.5/gcc_64/include/QtWidgets/qcombobox.h:279
#4  QComboBox::addItem () at ../../../Qt/5.12.5/gcc_64/include/QtWidgets/qcombobox.h:272
#5  PatientListenerComboBox::patientAdded () at ../DatabaseSelect/src/presentation/PatientListenerComboBox.cpp:18
#6  Root::addPatient () at ../DatabaseSelect/src/business/Root.cpp:15
#7  MainWindow::onPatientButtonAddClicked () at ../DatabaseSelect/src/presentation/MainWindow.cpp:164
#8  MainWindow::qt_static_metacall ()::InvokeMetaMethod, _id=3, _a=0x7fffffffd590) at moc_MainWindow.cpp:106
#9  QMetaObject::activate ()
#10 QMetaObject::activate ()::staticMetaObject>,
#11 QAbstractButton::clicked () at .moc/moc_qabstractbutton.cpp:312
#12 QAbstractButtonPrivate::emitClicked () at widgets/qabstractbutton.cpp:414
#13 QAbstractButtonPrivate::click () at widgets/qabstractbutton.cpp:407
#14 QAbstractButton::mouseReleaseEvent () at widgets/qabstractbutton.cpp:1011
#15 QToolButton::mouseReleaseEvent () at widgets/qtoolbutton.cpp:622
#16 QWidget::event () at kernel/qwidget.cpp:9327
#17 QAbstractButton::event () at widgets/qabstractbutton.cpp:968
#18 QToolButton::event () at widgets/qtoolbutton.cpp:1001
#19 QApplicationPrivate::notify_helper () at kernel/qapplication.cpp:3700
#21 QCoreApplication::notifyInternal2 () at kernel/qcoreapplication.cpp:1088
#22 QCoreApplication::sendSpontaneousEvent () at kernel/qcoreapplication.cpp:1488
#23 QApplicationPrivate::sendMouseEvent ()
#24 QWidgetWindow::handleMouseEvent () at kernel/qwidgetwindow.cpp:663
#25 QWidgetWindow::event () at kernel/qwidgetwindow.cpp:281
#26 QApplicationPrivate::notify_helper () at kernel/qapplication.cpp:3700
#27 QApplication::notify () at kernel/qapplication.cpp:3446
#28 QCoreApplication::notifyInternal2 () at kernel/qcoreapplication.cpp:1088
#29 QCoreApplication::sendSpontaneousEvent () at kernel/qcoreapplication.cpp:1488
#30 QGuiApplicationPrivate::processMouseEvent () at kernel/qguiapplication.cpp:2107
#31 QGuiApplicationPrivate::processWindowSystemEvent () at kernel/qguiapplication.cpp:1842.
#32 QWindowSystemInterface::sendWindowSystemEvents () at kernel/qwindowsysteminterface.cpp:1151
#33 xcbSourceDispatch () at qxcbeventdispatcher.cpp:105
#34 g_main_context_dispatch () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#35 ?? () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#36 g_main_context_iteration () from /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#37 QEventDispatcherGlib::processEvents () at kernel/qeventdispatcher_glib.cpp:422
#38 QEventLoop::exec () at kernel/qeventloop.cpp:225
#39 QCoreApplication::exec () at kernel/qcoreapplication.cpp:1389
#40 main () at ../DatabaseSelect/src/main.cpp:55

Model

Qt/5.12.3/Src/qtbase/src/corelib/itemmodels/qabstractitemmodel.h

Qt/5.12.3/Src/qtbase/src/gui/itemmodels/qstandarditemmodel.h

class QStandardItemPrivate
{
    [...]

    QStandardItemModel *model;
    QStandardItem *parent;
    QVector<QStandardItemData> values;
    QVector<QStandardItem*> children;
    int rows;
    int columns;

    QStandardItem *q_ptr;

    [...]
};

void
QStandardItemModel::setItem(int row,
                            int column,
                            QStandardItem *item)
{
    Q_D(QStandardItemModel);
    d->root->d_func()->setChild(row, column, item, true);
}

void
QStandardItemPrivate::setChild(int row,
                               int column,
                               QStandardItem *item,
                               bool emitChanged)
{
    [...]
}

QVariant
QStandardItemModel::data(const QModelIndex &index,
                         int role) const
{
    Q_D(const QStandardItemModel);
    QStandardItem *item = d->itemFromIndex(index);
    return item ? item->data(role) : QVariant();
}

QVariant
QStandardItem::data(int role) const
{
    Q_D(const QStandardItem);
    role = (role == Qt::EditRole) ? Qt::DisplayRole : role;
    QVector<QStandardItemData>::const_iterator it;
    for (it = d->values.begin(); it != d->values.end(); ++it) {
        if ((*it).role == role)
            return (*it).value;
    }
    return QVariant();
}

void
QStandardItem::setRowCount(int rows)
{
    int rc = rowCount();
    if (rc == rows)
        return;
    if (rc < rows)
        insertRows(qMax(rc, 0), rows - rc);
    else
        removeRows(qMax(rows, 0), rc - rows);
}

void
QStandardItem::insertRows(int row,
                          const QList<QStandardItem*> &items)
{
    Q_D(QStandardItem);
    if (row < 0)
        return;
    d->insertRows(row, items);
}

bool
QStandardItemPrivate::insertRows(int row,
                                 int count,
                                 const QList<QStandardItem*> &items)
{
    [...]

    if (model)
        model->d_func()->rowsAboutToBeInserted(q, row, row + count - 1);

    [...]

    if (model)
        model->d_func()->rowsInserted(q, row, count);

    return true;
}

View

Qt/5.12.3/Src/qtbase/src/widgets/widgets/qcombobox.h

Qt/5.12.5/Src/qtbase/src/widgets/itemviews/qabstractitemview.h

/*!
    This slot is called when items with the given \a roles are changed in the
    model. The changed items are those from \a topLeft to \a bottomRight
    inclusive. If just one item is changed \a topLeft == \a bottomRight.

    The \a roles which have been changed can either be an empty container (meaning everything
    has changed), or a non-empty container with the subset of roles which have changed.
*/
void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
    [...]
}

Qt/5.12.5/Src/qtbase/src/widgets/itemviews/qtreeview.h

/*!
  \reimp
*/
void QTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
    [...]
    QAbstractItemView::dataChanged(topLeft, bottomRight, roles);
}

Qt Serial Port

Qt Serial Port
Qt Serial Port Examples
Qt 5.12 Qt Serial Port Command Line Reader Sync Example main.cpp Example File
Qt 5.12 Qt Serial Port Qt Serial Port Examples Command Line Enumerator Example
Qt 5.12 Qt Serial Port Qt Serial Port Examples Blocking Master Example
Qt Serial Port

$ grep -Er "emit \w*[->.]*w*readyRead"
qtbase/dist/changes-4.3.0:    * [142853] Now continues to emit readyRead() if the peer temporarily
qtbase/src/corelib/doc/snippets/code/src_corelib_io_qprocess.cpp:// QProcess will emit readyRead() once "more" starts printing
qtbase/src/corelib/io/qbuffer.cpp:    emit q->readyRead();
qtbase/src/corelib/io/qiodevice.cpp:    you should always emit readyRead() when new data has arrived (do not
qtbase/src/corelib/io/qiodevice.cpp:    buffers). Do not emit readyRead() in other conditions.
qtbase/src/corelib/io/qiodevice.cpp:    which channel triggers QIODevice to emit readyRead().
qtbase/src/corelib/io/qprocess.cpp:            emit q->readyRead();
qtbase/src/corelib/io/qprocess.cpp:        emit q->readyReadStandardOutput(QProcess::QPrivateSignal());
qtbase/src/corelib/io/qprocess.cpp:        emit q->readyReadStandardError(QProcess::QPrivateSignal());
qtbase/src/corelib/io/qprocess.cpp:    which channel triggers QProcess to emit readyRead().
qtbase/src/corelib/io/qprocess.cpp:    function, QProcess will no longer emit readyRead(), and data can no
qtbase/src/corelib/io/qwindowspipereader.cpp:        emit readyRead();
qtbase/src/network/access/qftp.cpp:            emit readyRead();
qtbase/src/network/access/qhttp2protocolhandler.cpp:                emit httpReply->readyRead();
qtbase/src/network/access/qhttpnetworkconnectionchannel.cpp:            emit reply->readyRead();
qtbase/src/network/access/qhttpprotocolhandler.cpp:                    emit m_reply->readyRead();
qtbase/src/network/access/qhttpprotocolhandler.cpp:                        emit m_reply->readyRead();
qtbase/src/network/access/qhttpthreaddelegate_p.h:        emit readyRead();
qtbase/src/network/access/qnetworkreplyhttpimpl.cpp:    emit q->readyRead();
qtbase/src/network/access/qnetworkreplyhttpimpl.cpp:    // emit readyRead before downloadProgress incase this will cause events to be
qtbase/src/network/access/qnetworkreplyhttpimpl.cpp:    // Only emit readyRead when actual data is there
qtbase/src/network/access/qnetworkreplyhttpimpl.cpp:    // emit readyRead before downloadProgress incase this will cause events to be
qtbase/src/network/access/qnetworkreplyhttpimpl.cpp:        emit q->readyRead();
qtbase/src/network/access/qnetworkreplyhttpimpl.cpp:        // No bytes from upload byte device. There will be bytes later, it will emit readyRead()
qtbase/src/network/access/qnetworkreplyhttpimpl.cpp:    // emit readyRead before downloadProgress incase this will cause events to be
qtbase/src/network/access/qnetworkreplyhttpimpl.cpp:        emit q->readyRead();
qtbase/src/network/access/qnetworkreplyimpl.cpp:    // emit readyRead before downloadProgress incase this will cause events to be
qtbase/src/network/access/qnetworkreplyimpl.cpp:    emit q->readyRead();
qtbase/src/network/access/qnetworkreplyimpl.cpp:    emit q->readyRead();
qtbase/src/network/access/qnetworkreplyimpl.cpp:    // emit readyRead before downloadProgress incase this will cause events to be
qtbase/src/network/access/qnetworkreplyimpl.cpp:    // Only emit readyRead when actual data is there
qtbase/src/network/access/qnetworkreplyimpl.cpp:    // emit readyRead before downloadProgress incase this will cause events to be
qtbase/src/network/access/qnetworkreplyimpl.cpp:        emit q->readyRead();
qtbase/src/network/access/qnetworkreplywasmimpl.cpp:    emit q->readyRead();
qtbase/src/network/access/qspdyprotocolhandler.cpp:        emit httpReply->readyRead();
qtbase/src/network/socket/qabstractsocket.cpp:    // Only emit readyRead() when not recursing.
qtbase/src/network/socket/qabstractsocket.cpp:        emit q->readyRead();
qtbase/src/network/ssl/qsslsocket.cpp:        emit q->readyRead();
qtbase/src/network/ssl/qsslsocket_mac.cpp:                emit q->readyRead();
qtbase/src/network/ssl/qsslsocket_openssl.cpp:                emit q->readyRead();
qtbase/src/network/ssl/qsslsocket_winrt.cpp:        emit q->readyRead();
qtbase/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp:        emit readyRead();
qtbase/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp:        emit readyRead();
qtbase/tests/auto/xml/sax/qxmlinputsource/tst_qxmlinputsource.cpp:            emit readyRead();
qtbase/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp:    void start() { state = Started; emit readyRead(); }
qtbase/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp:    void stop() { state = Stopped; emit readyRead(); }
qtbase/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp:    void start() { state = Started; emit readyRead(); }
qtconnectivity/src/bluetooth/qbluetoothsocket_bluez.cpp:        emit q->readyRead();
qtconnectivity/src/bluetooth/qbluetoothsocket_osx.mm:                emit q_ptr->readyRead();
qtconnectivity/src/bluetooth/qbluetoothsocket_osx.mm:        emit q_ptr->readyRead();
qtconnectivity/src/bluetooth/qbluetoothsocket_osx.mm:    }   // else connectToService must check and emit readyRead!
qtconnectivity/src/bluetooth/qbluetoothsocket_winrt.cpp:    emit q->readyRead();
qtconnectivity/src/nfc/qllcpsocket_android_p.cpp:        emit q->readyRead();
qtdeclarative/src/plugins/qmltooling/packetprotocol/qpacketprotocol.cpp:                emit readyRead();
qtdeclarative/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp:        emit readyReadStandardOutput();
qtdeclarative/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp:        emit readyRead();
qtmultimedia/src/plugins/alsa/qalsaaudioinput.cpp:    emit readyRead();
qtmultimedia/src/plugins/coreaudio/coreaudioinput.mm:        emit readyRead();
qtmultimedia/src/plugins/coreaudio/coreaudiooutput.mm:        emit readyRead();
qtmultimedia/src/plugins/coreaudio/coreaudiooutput.mm:            emit readyRead();
qtmultimedia/src/plugins/pulseaudio/qaudioinput_pulse.cpp:    emit readyRead();
qtmultimedia/src/plugins/qnx-audio/audio/qnxaudioinput.cpp:    emit readyRead();
qtmultimedia/src/plugins/wasapi/qwasapiaudioinput.cpp:        emit m_eventDevice->readyRead();
qtmultimedia/src/plugins/windowsaudio/qwindowsaudioinput.cpp:    emit readyRead();
qtmultimedia/src/plugins/windowsaudio/qwindowsaudioinput.cpp:    emit readyRead();
qtremoteobjects/src/remoteobjects/qconnection_qnx_server.cpp:            emit io->readyRead();
qtserialport/src/serialport/qserialport_unix.cpp:    // only emit readyRead() when not recursing, and only if there is data available
qtserialport/src/serialport/qserialport_unix.cpp:        emit q->readyRead();
qtserialport/src/serialport/qserialport_win.cpp:    emit q->readyRead();
qtwebengine/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp:        emit readyRead();
qtwebsockets/src/websockets/qwebsocketserver_p.cpp:            emit pTcpSocket->readyRead();

Qt Layouts with Designer

CleanQt

Crash course in Qt for C++ developers, Part 1

Bits of Bytes – bits of coding, C++, Qt, git, gamedev, linux and other tech stuff

How to create an application with Qt and C++
How to embed a database in your application with SQLite and Qt
Qt Network and JSON example: a simple Hacker News reader
How to traverse a git repository using libgit2 and C++

Qt – setupUi()
User Interfaces
Widgets Classes
Qt Quick UI Forms
What is the use of the ui.qml files in Qt5 (QML)?
Best Practices for QML and Qt Quick

QML (Qt Meta-object Language)

Qt Layouts without Designer

Layouts without Designer

Alignment

Aligning qlabel text in centre
QLabel text align wit StyleSheet
setAlignment in Layout
Qt: Align Text Center and Left using StyleSheet

QSizePolicy, SizeHint, Stretch

QSizePolicy Class

Can’t get a widget to grow properly when I resize the window
Understanding form layout mechanisms in Qt
Qt SizePolicy and sizeHint
How to properly size Qt widgets?

enum Qt::AlignmentFlag / flags Qt::Alignment

Qt Namespace

Constant Value Description
Qt::AlignLeft 0x0001 Aligns with the left edge.
Qt::AlignRight 0x0002 Aligns with the right edge.
Qt::AlignHCenter 0x0004 Centers horizontally in the available space.
Qt::AlignJustify 0x0008 Justifies the text in the available space.
Qt::AlignTop 0x0020 Aligns with the top.
Qt::AlignBottom 0x0040 Aligns with the bottom.
Qt::AlignVCenter 0x0080 Centers vertically in the available space.
Qt::AlignBaseline 0x0100 Aligns with the baseline.

Qt Threads

Must-Read Site

How To Really, Truly Use QThreads; The Full Explanation
Does large use of signals and slots affect application performance?

Qt Documentation

Thread Support in Qt
QThread Class
Threading Basics
Threading Basics (Qt 4.8)
Threading and Concurrent Programming Examples
Synchronizing Threads
Multithreading Technologies in Qt
QCoreApplication::processEvents

Qt Wiki

Threads Events QObjects
QThreads general usage

Tutorials

The Missing Article About Qt Multithreading in C++
How To Really, Truly Use QThreads; The Full Explanation
Qt with Cascades UI Examples Documentation

StackOverflow

How to stop a qThread in QT [duplicate]
Sending a sequence of commands and wait for response
QThreads , QObject and sleep function
What is the use of QThread.wait() function?
(QT) QThread not executing a second time
What is the use of QThread.wait() function?