Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7178181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:52:10+00:00 2026-05-28T16:52:10+00:00

I have a custom data structure that I want to display in a PyQt

  • 0

I have a custom data structure that I want to display in a PyQt application using a QTableView. I’m using a subclass of QAbstractTableModel to communicate with the data. The data structure itself is in a separate module and knows nothing about PyQt.

Displaying and editing the data with the QTableView works, but now I’d like to sort the data and then update the model and view.

After reading the Qt documentation for QAbstractTableModel and its ancestor QAbstractItemModel, my first approach was to try this:

class MyModel(QtCore.QAbstractTableModel):
    __init__(self, data_structure):
        super().__init__()
        self.data_structure = data_structure

    # ...

    def sort_function(self):
        self.layoutAboutToBeChanged.emit()
        # custom_sort() is built into the data structure
        self.data_structure.custom_sort()
        self.layoutChanged.emit()

However, this fails to update the view. I also tried emitting a dataChanged signal on all of the data being used by the model, but this failed to update the view as well.

I did some further research. If I understand correctly, the problem is that the QPersistentModelIndexes in the model are not getting updated, and the solution would be to manually update them somehow.

Is there a better way to do this? If not, how would I go about updating them (preferably without having to write a new sort function that tracks every index change)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:52:11+00:00Added an answer on May 28, 2026 at 4:52 pm

    There was a bug in the custom_sort() function. After fixing it, the approach I described here works.

    class MyModel(QtCore.QAbstractTableModel):
        __init__(self, data_structure):
            super().__init__()
            self.data_structure = data_structure
    
        # ...
    
        def sort_function(self):
            self.layoutAboutToBeChanged.emit()
            # custom_sort() is built into the data structure
            self.data_structure.custom_sort()
            self.layoutChanged.emit()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have a tree display custom data that looks like this.
I have a wpf app that needs to communicate(exchange data) with a custom designed
I have a custom read-only data structure that I need to transverse. I would
I have a custom data structure that is pretty much a list of string
I have a custom NSTableView subclass which is bound to a data source (an
I have a data object -- a custom class called Notification -- that exposes
I have an interface in C# that helps retrieving of data from a custom
I have a list called list_ds of a custom-defined data structure in my OCaml
I want to write a Parser that produces some data structure and validates its
I have a slow custom data source in a SSIS Dataa Flow Task.I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.