Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Pyside2] Representing data from databse in QListView and allowing rows to be sorted by columns.
Forum Updated to NodeBB v4.3 + New Features

[Pyside2] Representing data from databse in QListView and allowing rows to be sorted by columns.

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 387 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RaisinBread22
    wrote on last edited by RaisinBread22
    #1

    I have a simple Sqlite database table where each row contains 3 values: a name, date, and image file path. Each time a particular event(that pertains to my application) is performed by the user, a new row is added with the users' name, the date of the event, and a file path to a screenshot of the event. A table might look somewhat like this:

    alt text

    I want to create a QtableView that uses a portion the data in the database table: the names and dates, in addition to the number of times each user is in the database(equal to the # of events they've performed). I want the QtableView by default to be sorted in descending order by the number of times each user has performed an event, with their most recent event date. The Qtableview in default order would look like this:

    alt text

    However, the user can click either the Name, Events or Date column headers, which should reorganize the rows corresponding to that column's values after they've been sorted. For instance, If the user clicks the Date column header I want to to sort all rows corresponding to the Date column after it has been sorted with the most recent date first. As another example, if the user clicks the Name column header, I sort the rows corresponding to the Name column after it has been sorted in alphabetical order. For instance here's what the Qtableview should look like after I've sorted by Name:

    alt text

    As I see it there are two main times when I'll need to update the QTableView: when the application first starts up, and each time a new row is added to the database(the user performs an event). Upon the startup of the Qt application, I'll be able to call a function I've defined in the database class that tells me all of the user's names, the number of events they've performed and the most recent event date. Each time a new row is added to the database after a user
    performs an event, I send a signal to the main Qt event loop from the database class, so I can update the view with that new row.

    My question: What type of model should I use to store this data? What functions might I need to overload to reorganize the QTableView every time the user clicks one of the column headers? Is QTableView overkill, should I use QTablewidget instead? Or is QTableView appropriate?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Looks like you should take a look at QSortFilterProxyModel.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved