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 7908245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:50:57+00:00 2026-06-03T11:50:57+00:00

What would be the most efficient and technically ( Python/PyQt4 ) correct way of

  • 0

What would be the most efficient and technically (Python/PyQt4) correct way of making arbitrary muti-selection in a QTableView which has a model encompassing hierarchy of QStandardItems (a graph plot data) with custom isSelected data attribute added per item.

In details: Along with the table I have a matplotlib plot which outputs ranges (isSelected attribute comes directly from these ranges) that correspond to my QTableView data and I want to add a bit of interaction between these two gui elements.

i.e matplotlib plot selection is reflected in QTableView and vice versa (which I’m getting by hooking selection change to reading corresponding indexes and feeding them back to graph plot).

Hopefully this explanation makes sense. Thanks.

  • 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-06-03T11:51:01+00:00Added an answer on June 3, 2026 at 11:51 am

    As you said, right now you have your QTableView.selectionChanged() feeding the selections back to your matplot. The most efficient approach would be to have your matplot emit a signal for its selection, with the relevant items.

    A table view already stores its selections in a QItemSelectionModel, so as far as I can see it would be redundant and unnecessary to store your own isSelected attribute on the items. Your matplot view should know the items it is using and should be able to notify the table view of its selection changes.

    Your matplot view can have a signal that you emit, such as selectionChanged(items), and can continue having no knowledge of the table view.

    Your table view, as it already knows about the matplot view, can connect to its selectionChanged(items) to the matplot and listen for selection changes. Even if your table is also emitting a signal and has no knowledge of the matplot, you can make the connection in whatever parent class does know of them both.

    This is why I think the attribute isn’t needed: The only way to make use of that attribute is to scan the entire model, checking each item. Thats not really efficient. The selection should happen in reaction to the signal being emitted.

    myMatPlotView.selectionchanged.connect(myTableView.matplotSelected)
    

    And in your matPlotSelected() slot, you can use the selection model to set the items selection:

    tableView

    def matPlotSelected(self, qStandardItems):
    
        selModel = self.selectionModel()
        model = self.model()
    
        for item in qStandardItems:
            idx = model.indexFromItem(item)
            selModel.select(idx, selModel.Select)
    

    Update

    In the comments you provided a code snippet, which really helped to isolate what you want to achieve.

    Your example

    def __init__(self):
        super(myDialog, self).__init__()
        self.t = QtGui.QTreeView()
        self.m = QtGui.QStandardItemModel()
        self.t.setModel(self.m)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.t)
        self.setLayout(layout)
        self.l = [
            ['one', False], ['two', True], 
            ['three', False], ['four', True], 
            ['five', False]]
        self.populate()
    
    def populate(self):
        self.m.clear()
        root = self.m.invisibleRootItem()
        for item in self.l:
            e = QtGui.QStandardItem()
            e.setText(item[0])
            root.appendRow(e)
    

    If this is your actual situation, then what I suggested above fits in like this:

    def populate(self):
        self.m.clear()
        root = self.m.invisibleRootItem()
        selModel = self.t.selectionModel()
        for item in self.l:
            e = QtGui.QStandardItem()
            e.setText(item[0])
            root.appendRow(e)
    
            if item[1]:
                idx = self.m.indexFromItem(e)
                selModel.select(idx, selModel.Select)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the Twitter API, what would be the most efficient way to find which
What would be the most efficient way of recording to a log (.txt) from
What would be the most efficient way of counting the number of times a
I have this string: B82V16814133260 what would be the most efficient way to get
If I have a json like follows, what would be the most efficient way
If I have two associative arrays, what would be the most efficient way of
What would be the most efficient way to read a UInt32 value from an
What would be the most efficient way to set customized formatting of the column
What would be the most efficient way to cover all cases for a retrieve
What would be the most efficient way to instanciate an object according to a

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.