I just want to use the virtual sort() function of QSortFilterProxyModel class to sort my columns in my list view if the header/column title is clicked()...
I add a UserEventModelProxy class that sub classes QSortFilterPRoxyModel class (I only create a construct cuase I just want to use a the virtual function sort() and this function should get called when the constructor dose...)
I created an instance of my UserEventModelProxy class to use in my UserEventLog class
I set the sourceModel and set the sortRole to UserEventLog::dateRole
then set the sort to the date column (it seems this sort is ran when the model is going to populate and not on a signal I want to sort on signal I don’t want sort to happen before)
I need to connect the column title/head to the sort() virtual function call...
#include "usereventlog.h"
//---UserEvent-SortModelProxy---//
}
//----------End QSortFilterProxy----------//
//------Begin UserEventLog Class/Model-------//
//---allocates dynamic memory on heap | new instance of proxyModel class---//
m_UserEventModelProxy = new UserEventModelProxy(this);
//---Sets the model the proxySort will use e.g. UserEventLog Model---//
m_UserEventModelProxy->setSourceModel(this);
//---property holds the item role that is used to query the source model's data when sorting items---//
m_UserEventModelProxy->setSortRole(UserEventLog::dateRole);
//---Sorts the model by column in the given order---//
//---Date Column---//
m_UserEventModelProxy->sort(4);
}
UserEventLog::~UserEventLog(){
}
int UserEventLog
::rowCount(const QModelIndex &parent
) const{ Q_UNUSED(parent);
return m_userEventList.count();
}
QHash<int, QByteArray> UserEventLog::roleNames() const{
QHash<int, QByteArray> roleNames;
roleNames.insert(idRole, "id");
roleNames.insert(nameRole, "userName");
roleNames.insert(msgRole, "eventMessage");
roleNames.insert(dateRole, "dateTime");
return roleNames;
}
if (index.row() < 0 || index.row() >= m_userEventList.count()){
}
if(role == idRole){
userEventLogMsg msg = m_userEventList.at(index.row());
text = msg.id;
}
else if(role == nameRole){
userEventLogMsg msg = m_userEventList.at(index.row());
text = msg.username;
}
else if(role == msgRole){
userEventLogMsg msg = m_userEventList.at(index.row());
text = msg.eventmessage;
}
if(role == dateRole){
userEventLogMsg msg = m_userEventList.at(index.row());
text = msg.datetime;
}
return text;
}
void UserEventLog::addEvent(const userEventLogMsg &msg){
m_userEventList.insert(0, msg);
endInsertRows();
}
void UserEventLog::init(){
//emit showBusy(true);
dbConnect();
archiveEvent();
selectEvent();
//emit showBusy(false);
}
bool UserEventLog::dbConnect(){
//---check if database is connected---//
if(!m_selectDataBase.isValid()){
qDebug() << "error in connecting to DB";
m_selectDataBase
= QSqlDatabase::addDatabase("QSQLITE",
"conn2");
m_selectDataBase.setDatabaseName(Paths::root() + "/userLog.db");
qDebug() << "database connect path: "+Paths::root()+"/userLog.db";
m_selectDataBase.open();
}
else{
qDebug() <<"connected to DB" ;
m_selectDataBase.open();
}
return m_selectDataBase.isValid();
}
bool UserEventLog::selectEvent(){
dbConnect();
emit showBusy(true);
QSqlQuery selectQuery
("SELECT * FROM userlogevents WHERE dateTime BETWEEN ? and ?", m_selectDataBase
);
selectQuery.addBindValue(beginDate);
selectQuery.addBindValue(endDate);
if(selectQuery.exec()){
qDebug()<<"sql statement executed fine";
}
else{
emit xmui
->alertMsg
(QMessageBox::Warning,
"Database Error Message 1",
"Error: sql select script..."+selectQuery.
lastError().
text());
return selectQuery.exec();
}
userEventLogMsg msg;
beginResetModel();
m_userEventList.clear();
while (selectQuery.next()){
msg.id = selectQuery.value(0).toString();
msg.username = selectQuery.value(1).toString();
msg.eventmessage = selectQuery.value(2).toString();
msg.datetime = selectQuery.value(3).toString();
addEvent(msg);
}
endResetModel();
emit showBusy(false);
m_selectDataBase.close();
return selectQuery.exec();
}
#include "usereventlog.h"
//---UserEvent-SortModelProxy---//
UserEventModelProxy::UserEventModelProxy(QObject *parent) : QSortFilterProxyModel(parent){
}
//----------End QSortFilterProxy----------//
//------Begin UserEventLog Class/Model-------//
UserEventLog::UserEventLog(QObject *parent):QAbstractListModel(parent){
//---allocates dynamic memory on heap | new instance of proxyModel class---//
m_UserEventModelProxy = new UserEventModelProxy(this);
//---Sets the model the proxySort will use e.g. UserEventLog Model---//
m_UserEventModelProxy->setSourceModel(this);
//---property holds the item role that is used to query the source model's data when sorting items---//
m_UserEventModelProxy->setSortRole(UserEventLog::dateRole);
//---Sorts the model by column in the given order---//
//---Date Column---//
m_UserEventModelProxy->sort(4);
}
UserEventLog::~UserEventLog(){
}
int UserEventLog::rowCount(const QModelIndex &parent) const{
Q_UNUSED(parent);
return m_userEventList.count();
}
QHash<int, QByteArray> UserEventLog::roleNames() const{
QHash<int, QByteArray> roleNames;
roleNames.insert(idRole, "id");
roleNames.insert(nameRole, "userName");
roleNames.insert(msgRole, "eventMessage");
roleNames.insert(dateRole, "dateTime");
return roleNames;
}
QVariant UserEventLog::data(const QModelIndex &index, int role) const{
if (index.row() < 0 || index.row() >= m_userEventList.count()){
return QVariant();
}
QVariant text;
if(role == idRole){
userEventLogMsg msg = m_userEventList.at(index.row());
text = msg.id;
}
else if(role == nameRole){
userEventLogMsg msg = m_userEventList.at(index.row());
text = msg.username;
}
else if(role == msgRole){
userEventLogMsg msg = m_userEventList.at(index.row());
text = msg.eventmessage;
}
if(role == dateRole){
userEventLogMsg msg = m_userEventList.at(index.row());
text = msg.datetime;
}
return text;
}
void UserEventLog::addEvent(const userEventLogMsg &msg){
beginInsertRows(QModelIndex(), 0, 0);
m_userEventList.insert(0, msg);
endInsertRows();
}
void UserEventLog::init(){
//emit showBusy(true);
dbConnect();
archiveEvent();
selectEvent();
//emit showBusy(false);
}
bool UserEventLog::dbConnect(){
//---check if database is connected---//
if(!m_selectDataBase.isValid()){
qDebug() << "error in connecting to DB";
m_selectDataBase = QSqlDatabase::addDatabase("QSQLITE", "conn2");
m_selectDataBase.setDatabaseName(Paths::root() + "/userLog.db");
qDebug() << "database connect path: "+Paths::root()+"/userLog.db";
m_selectDataBase.open();
}
else{
qDebug() <<"connected to DB" ;
m_selectDataBase.open();
}
return m_selectDataBase.isValid();
}
bool UserEventLog::selectEvent(){
dbConnect();
QDate beginDate = QDate::currentDate();
QDate endDate = QDate::currentDate();
emit showBusy(true);
QSqlQuery selectQuery("SELECT * FROM userlogevents WHERE dateTime BETWEEN ? and ?", m_selectDataBase);
selectQuery.addBindValue(beginDate);
selectQuery.addBindValue(endDate);
if(selectQuery.exec()){
qDebug()<<"sql statement executed fine";
}
else{
emit xmui->alertMsg(QMessageBox::Warning, "Database Error Message 1", "Error: sql select script..."+selectQuery.lastError().text());
return selectQuery.exec();
}
userEventLogMsg msg;
beginResetModel();
m_userEventList.clear();
while (selectQuery.next()){
msg.id = selectQuery.value(0).toString();
msg.username = selectQuery.value(1).toString();
msg.eventmessage = selectQuery.value(2).toString();
msg.datetime = selectQuery.value(3).toString();
addEvent(msg);
}
endResetModel();
emit showBusy(false);
m_selectDataBase.close();
return selectQuery.exec();
}
To copy to clipboard, switch view to plain text mode
{
Q_OBJECT
public:
UserEventModelProxy
(QObject *parent
= 0);
};
//---Data struct for user event log---//
struct userEventLogMsg{
//---hold all values for a single list entry---//
};
//---Class UserEventDailyLog | Subed classed: QAbstractTableModel---//
{
Q_OBJECT
public:
explicit UserEventLog
(QObject *parent
= 0);
~UserEventLog();
enum userEventRoles {idRole= Qt::UserRole + 220, nameRole, msgRole, dateRole};
QHash<int, QByteArray> roleNames() const;
Q_INVOKABLE void addEvent(const userEventLogMsg &msg);
Q_INVOKABLE bool archiveEvent();
Q_INVOKABLE bool selectEvent();
Q_INVOKABLE bool dbConnect();
Q_INVOKABLE void init();
Q_INVOKABLE
bool searchDate
(QDate userDateText
);
Q_INVOKABLE
bool searchUserName
(QString userNameText
);
Q_INVOKABLE
bool searchUserNameDateText
(QString userNameText,
QDate userDateText
);
Q_INVOKABLE
bool searchDateRange
(QDate beginDate,
QDate endDate
);
Q_INVOKABLE
bool searchDateRange
(const QString &userName,
QDate beginDate,
QDate endDate
);
signals:
void showBusy(bool busy_state);
private:
QList<userEventLogMsg> m_userEventList;
//---Instance of proxy model class---//
UserEventModelProxy *m_UserEventModelProxy;
};
//--------------------End of userLogEvent Class-----------------//
class UserEventModelProxy : public QSortFilterProxyModel
{
Q_OBJECT
public:
UserEventModelProxy(QObject *parent = 0);
};
//---Data struct for user event log---//
struct userEventLogMsg{
//---hold all values for a single list entry---//
QString id;
QString username;
QString eventmessage;
QString datetime;
};
//---Class UserEventDailyLog | Subed classed: QAbstractTableModel---//
class UserEventLog : public QAbstractListModel
{
Q_OBJECT
public:
explicit UserEventLog(QObject *parent = 0);
~UserEventLog();
enum userEventRoles {idRole= Qt::UserRole + 220, nameRole, msgRole, dateRole};
int rowCount(const QModelIndex & parent) const;
QHash<int, QByteArray> roleNames() const;
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
Q_INVOKABLE void addEvent(const userEventLogMsg &msg);
Q_INVOKABLE bool archiveEvent();
Q_INVOKABLE bool selectEvent();
Q_INVOKABLE bool dbConnect();
Q_INVOKABLE void init();
Q_INVOKABLE bool searchDate(QDate userDateText);
Q_INVOKABLE bool searchUserName(QString userNameText);
Q_INVOKABLE bool searchUserNameDateText(QString userNameText, QDate userDateText);
Q_INVOKABLE bool searchDateRange(QDate beginDate, QDate endDate);
Q_INVOKABLE bool searchDateRange(const QString &userName, QDate beginDate, QDate endDate);
signals:
void showBusy(bool busy_state);
void alertDbMsg(int icon, QString title, QString msg_text);
private:
QList<userEventLogMsg> m_userEventList;
QSqlDatabase m_selectDataBase;
QSqlQuery m_selectQuery;
//---Instance of proxy model class---//
UserEventModelProxy *m_UserEventModelProxy;
};
//--------------------End of userLogEvent Class-----------------//
To copy to clipboard, switch view to plain text mode
//-------------Create instance of class | Set the context property to expose C++ to QML------------//
mUserEventLogModel = new UserEventLog();
m_QmlEngine->rootContext()->setContextProperty("UserEventLog", mUserEventLogModel);
mUserEventProxyModel = new UserEventModelProxy();
m_QmlEngine->rootContext()->setContextProperty("UserEventProxyModel", mUserEventProxyModel);
//--------------------------------------------------------------//
//-------------Create instance of class | Set the context property to expose C++ to QML------------//
mUserEventLogModel = new UserEventLog();
m_QmlEngine->rootContext()->setContextProperty("UserEventLog", mUserEventLogModel);
mUserEventProxyModel = new UserEventModelProxy();
m_QmlEngine->rootContext()->setContextProperty("UserEventProxyModel", mUserEventProxyModel);
//--------------------------------------------------------------//
To copy to clipboard, switch view to plain text mode
Added after 4 minutes:
qml
//---Column Headers for listView table---//
Rectangle {
id: eventMsg_panel
height: 30
radius: 8
color: "#141414"
anchors.right: parent.right
anchors.rightMargin: 6
anchors.left: parent.left
anchors.leftMargin: 5
anchors.top: parent.top
anchors.topMargin: 50
border.width: 5
border.color: "#00000000"
Rectangle{
id: labels
color: "#333131"
radius: 8
anchors.top: parent.top
anchors.topMargin: 0
border.color: "#00000000"
border.width: 2
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.left: parent.left
Rectangle{
id: id_col
width: 100
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
color: "#00000000"
Text {
color: "#ffffff"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
verticalAlignment: Text.AlignVCenter
text: "ID";
font.pixelSize: 20
horizontalAlignment: Text.AlignHCenter
font.bold: false
}
}
Rectangle{
id:divider1
width:3
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: id_col.right
color: "#8a8a8a"
}
Rectangle{
id: userName_col
width: 150
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: divider1.right
color: "#00000000"
Text {
color: "#ffffff"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
verticalAlignment: Text.AlignVCenter
text: "User Name";
font.pixelSize: 20
horizontalAlignment: Text.AlignHCenter
font.bold: false
}
}
Rectangle{
id:divider2
width:3
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: userName_col.right
color: "#8a8a8a"
}
Rectangle{
id: eventMsg_col
height: 25
width: 200
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: divider2.right
anchors.right: parent.right
color: "#00000000"
anchors.rightMargin: 156
Text {
height: 20
color: "#ffffff"
verticalAlignment: Text.AlignVCenter
text: "Event Message";
anchors.horizontalCenterOffset: -50
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 20
font.bold: false
}
}
Rectangle{
id:divider3
width:3
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: eventMsg_col.right
color: "#8a8a8a"
}
Rectangle{
id: dateTime_col
width: 150
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: divider3.right
color: "#00000000"
Text {
color: "#ffffff"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
verticalAlignment: Text.AlignVCenter
text: "Date";
font.pixelSize: 20
horizontalAlignment: Text.AlignHCenter
font.bold: false
}
}
}
}
//---Column Headers for listView table---//
Rectangle {
id: eventMsg_panel
height: 30
radius: 8
color: "#141414"
anchors.right: parent.right
anchors.rightMargin: 6
anchors.left: parent.left
anchors.leftMargin: 5
anchors.top: parent.top
anchors.topMargin: 50
border.width: 5
border.color: "#00000000"
Rectangle{
id: labels
color: "#333131"
radius: 8
anchors.top: parent.top
anchors.topMargin: 0
border.color: "#00000000"
border.width: 2
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.left: parent.left
Rectangle{
id: id_col
width: 100
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
color: "#00000000"
Text {
color: "#ffffff"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
verticalAlignment: Text.AlignVCenter
text: "ID";
font.pixelSize: 20
horizontalAlignment: Text.AlignHCenter
font.bold: false
}
}
Rectangle{
id:divider1
width:3
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: id_col.right
color: "#8a8a8a"
}
Rectangle{
id: userName_col
width: 150
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: divider1.right
color: "#00000000"
Text {
color: "#ffffff"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
verticalAlignment: Text.AlignVCenter
text: "User Name";
font.pixelSize: 20
horizontalAlignment: Text.AlignHCenter
font.bold: false
}
}
Rectangle{
id:divider2
width:3
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: userName_col.right
color: "#8a8a8a"
}
Rectangle{
id: eventMsg_col
height: 25
width: 200
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: divider2.right
anchors.right: parent.right
color: "#00000000"
anchors.rightMargin: 156
Text {
height: 20
color: "#ffffff"
verticalAlignment: Text.AlignVCenter
text: "Event Message";
anchors.horizontalCenterOffset: -50
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 20
font.bold: false
}
}
Rectangle{
id:divider3
width:3
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: eventMsg_col.right
color: "#8a8a8a"
}
Rectangle{
id: dateTime_col
width: 150
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: divider3.right
color: "#00000000"
Text {
color: "#ffffff"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
verticalAlignment: Text.AlignVCenter
text: "Date";
font.pixelSize: 20
horizontalAlignment: Text.AlignHCenter
font.bold: false
}
}
}
}
To copy to clipboard, switch view to plain text mode
qml continued
//---Delegate Component for listView | controls key nav & highlighting---//
Component {
id: msgDelegate
Item {
id: active_eventMsg
anchors.left: parent.left
anchors.leftMargin: 5
anchors.right: parent.right
anchors.rightMargin:5
height: 30
//---Key Navigation Work Around (listView focus issue)---//
Keys.onDownPressed: listView.incrementCurrentIndex()
Keys.onUpPressed: listView.decrementCurrentIndex()
KeyNavigation.tab: userNameDropDown
activeFocusOnTab: true
//---Highlight Functionality---//
MouseArea {
anchors.fill: parent
onClicked: {
listView.focus = true
console.log("msgDelegate activeFocus: "+activeFocus)
listView.currentIndex = index
}
}
//---Rect display model data in listView---//
Rectangle{
id: id_rect
anchors.top: parent.top
anchors.left: parent.left
anchors.leftMargin: 2
width: id_col.width
height: parent.height
color: "#00000000"
Text {
color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
text: id;
font.pixelSize: 18
}
}
Rectangle{
id: userName_rect
anchors.top: parent.top
anchors.left: id_rect.right
anchors.leftMargin: 2
width: userName_col.width
height: parent.height
color: "#00000000"
Text {
color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
anchors.fill: parent
anchors.leftMargin: 2
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
text: userName;
font.pixelSize: 18
}
}
Rectangle{
id: eventMsg_rect
anchors.top: parent.top
anchors.left: userName_rect.right
anchors.leftMargin: 2
width: eventMsg_col.width
height: parent.height
color: "#00000000"
Text {
color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
anchors.fill: parent
anchors.leftMargin: 2
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
text: eventMessage;
font.pixelSize: 18
}
}
Rectangle{
id: dateTime_rect
anchors.top: parent.top
anchors.left: eventMsg_rect.right
anchors.leftMargin: 2
width: dateTime_col.width
anchors.right: parent.right
height: parent.height
color: "#00000000"
Text {
color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
anchors.fill: parent
anchors.leftMargin: 2
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
text: dateTime;
font.pixelSize: 18
}
}
}
}
//---Rect for listView---//
Rectangle {
id: listView_rect
radius: 8
anchors.top: eventMsg_panel.bottom
anchors.topMargin: 2
anchors.bottom: parent.bottom
anchors.bottomMargin: 65
anchors.left:parent.left
anchors.leftMargin: 5
anchors.right:parent.right
anchors.rightMargin: 6
border{
color: "black"
width: 3
}
//---Adds ScrollBars---//
ScrollView{
id: userEvent_scrollView
anchors.fill: parent
anchors.bottomMargin: 5
anchors.topMargin: 5
anchors.rightMargin: 5
anchors.leftMargin: 5
//---Enables flickable Area---//
flickableItem.interactive: true
//---ScrollBar Component---//
style: edit_scrollbar_style
ListView {
id: listView
anchors.fill: parent
model: UserEventLog
delegate: msgDelegate
keyNavigationWraps: true
KeyNavigation.tab: userNameDropDown
orientation : "Vertical"
snapMode: ListView.SnapToItem
boundsBehavior: Flickable.StopAtBounds
clip: true;
highlightMoveVelocity: 2000
highlight: Rectangle{
radius: 7;
color: "red"
}
}
}
}
//---Delegate Component for listView | controls key nav & highlighting---//
Component {
id: msgDelegate
Item {
id: active_eventMsg
anchors.left: parent.left
anchors.leftMargin: 5
anchors.right: parent.right
anchors.rightMargin:5
height: 30
//---Key Navigation Work Around (listView focus issue)---//
Keys.onDownPressed: listView.incrementCurrentIndex()
Keys.onUpPressed: listView.decrementCurrentIndex()
KeyNavigation.tab: userNameDropDown
activeFocusOnTab: true
//---Highlight Functionality---//
MouseArea {
anchors.fill: parent
onClicked: {
listView.focus = true
console.log("msgDelegate activeFocus: "+activeFocus)
listView.currentIndex = index
}
}
//---Rect display model data in listView---//
Rectangle{
id: id_rect
anchors.top: parent.top
anchors.left: parent.left
anchors.leftMargin: 2
width: id_col.width
height: parent.height
color: "#00000000"
Text {
color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
text: id;
font.pixelSize: 18
}
}
Rectangle{
id: userName_rect
anchors.top: parent.top
anchors.left: id_rect.right
anchors.leftMargin: 2
width: userName_col.width
height: parent.height
color: "#00000000"
Text {
color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
anchors.fill: parent
anchors.leftMargin: 2
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
text: userName;
font.pixelSize: 18
}
}
Rectangle{
id: eventMsg_rect
anchors.top: parent.top
anchors.left: userName_rect.right
anchors.leftMargin: 2
width: eventMsg_col.width
height: parent.height
color: "#00000000"
Text {
color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
anchors.fill: parent
anchors.leftMargin: 2
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
text: eventMessage;
font.pixelSize: 18
}
}
Rectangle{
id: dateTime_rect
anchors.top: parent.top
anchors.left: eventMsg_rect.right
anchors.leftMargin: 2
width: dateTime_col.width
anchors.right: parent.right
height: parent.height
color: "#00000000"
Text {
color: active_eventMsg.ListView.isCurrentItem ? "white" : "black"
anchors.fill: parent
anchors.leftMargin: 2
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
text: dateTime;
font.pixelSize: 18
}
}
}
}
//---Rect for listView---//
Rectangle {
id: listView_rect
radius: 8
anchors.top: eventMsg_panel.bottom
anchors.topMargin: 2
anchors.bottom: parent.bottom
anchors.bottomMargin: 65
anchors.left:parent.left
anchors.leftMargin: 5
anchors.right:parent.right
anchors.rightMargin: 6
border{
color: "black"
width: 3
}
//---Adds ScrollBars---//
ScrollView{
id: userEvent_scrollView
anchors.fill: parent
anchors.bottomMargin: 5
anchors.topMargin: 5
anchors.rightMargin: 5
anchors.leftMargin: 5
//---Enables flickable Area---//
flickableItem.interactive: true
//---ScrollBar Component---//
style: edit_scrollbar_style
ListView {
id: listView
anchors.fill: parent
model: UserEventLog
delegate: msgDelegate
keyNavigationWraps: true
KeyNavigation.tab: userNameDropDown
orientation : "Vertical"
snapMode: ListView.SnapToItem
boundsBehavior: Flickable.StopAtBounds
clip: true;
highlightMoveVelocity: 2000
highlight: Rectangle{
radius: 7;
color: "red"
}
}
}
}
To copy to clipboard, switch view to plain text mode
Added after 5 minutes:
"To make your data sortable, you can either implement sort() in your model, " -doc
I want to reimplement sort but not sure how and also don't want it sort anything when it first displays the model
Added after 39 minutes:
update: override the sort() method
added sortByColumn() method that call the sort function
need to connect it now...
void UserEventModelProxy::sortByColumn(int column, Qt::SortOrder order)
{
sort(column, order);
}
void UserEventModelProxy::sortByColumn(int column, Qt::SortOrder order)
{
sort(column, order);
}
To copy to clipboard, switch view to plain text mode
Added after 23 minutes:
can yo set the sort indicator for a listView?
Bookmarks