Created
August 26, 2017 20:54
-
-
Save eyllanesc/8704c7b2e42d88b3ccc28d64143b454a to your computer and use it in GitHub Desktop.
QSortFilterProxyModel Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QApplication> | |
#include <QSortFilterProxyModel> | |
#include <QStandardItemModel> | |
#include <QTableView> | |
int main(int argc, char *argv[]) | |
{ | |
QApplication a(argc, argv); | |
QTableView *table = new QTableView(); | |
QStandardItemModel *sourceModel = new QStandardItemModel(5, 2); | |
for( int r=0; r<5; r++ ) | |
for( int c=0; c<2; c++) | |
{ | |
QStandardItem *item = new QStandardItem( QString("Row:%0, Column:%1").arg(5-r).arg(2-c) ); | |
sourceModel->setItem(r, c, item); | |
} | |
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel; | |
table->setSortingEnabled(true); | |
proxyModel->setSourceModel(sourceModel); | |
table->setModel(proxyModel); | |
table->resizeColumnsToContents(); | |
table->resizeRowsToContents(); | |
table->show(); | |
return a.exec(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------- | |
# | |
# Project created by QtCreator 2017-08-26T15:35:47 | |
# | |
#------------------------------------------------- | |
QT += core gui | |
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |
TARGET = QSortFilterProxyModelExample | |
TEMPLATE = app | |
# The following define makes your compiler emit warnings if you use | |
# any feature of Qt which as been marked as deprecated (the exact warnings | |
# depend on your compiler). Please consult the documentation of the | |
# deprecated API in order to know how to port your code away from it. | |
DEFINES += QT_DEPRECATED_WARNINGS | |
# You can also make your code fail to compile if you use deprecated APIs. | |
# In order to do so, uncomment the following line. | |
# You can also select to disable deprecated APIs only up to a certain version of Qt. | |
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | |
SOURCES += \ | |
main.cpp | |
HEADERS += |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment