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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:06:20+00:00 2026-06-11T19:06:20+00:00

I’m using a QTableView to display contents of a QSqlTableModel along with using a

  • 0

I’m using a QTableView to display contents of a QSqlTableModel along with using a QSortFilterProxyModel to filter the records. In the following code I’ve managed to get the selected text to be displayed when a user clicks the cell (regardless if a filter is applied or not). However, it is always 1 click behind, the first click after start causes an IndexError: pop from empty list and when a new column is selected within the same row nothing happens.

I’ve tried selecting an index after I initialize the table, didn’t seems to do anything. I’m out of ideas of what to try next?

class TableViewer(QtGui.QWidget):

    self.model =  QSqlTableModel()
    self._proxyModel = QtGui.QSortFilterProxyModel()
    self._proxyModel.setSourceModel(self.model)

    self.tv= QTableView()
    self.tv.setModel(self._proxyModel)

   '''Call-able filter - pass in string to filter everything that doesn't match string'''
    QtCore.QObject.connect(self.textEditFilterBox,  QtCore.SIGNAL("textChanged(QString)"),     self._proxyModel.setFilterRegExp)


     def getItem(self):
         '''Retruns item text of selected item'''
         index = self.selectionModel.selectedIndexes().pop()
         if index.isValid():
             row = index.row()
             column = index.column()
             model = index.model()
             if hasattr(model, 'mapToSource'):
                 #proxy model
                 modelIndex = model.mapToSource(index)
                 print (modelIndex.row(), modelIndex.column())
                 return self.model.record(modelIndex.row()).field(modelIndex.column()).value().toString()
         return self.model.record(row).field(column).value().toString()

class MainWindow(QtGui.QMainWindow):

    #initialize TableViewer

    self.tblViewer.connect(self.tblViewer.tv.selectionModel(),
            SIGNAL(("currentRowChanged(QModelIndex,QModelIndex)")),
            self.tblItemChanged)

    def tblItemChanged(self, index):
        '''display text of selected item '''
        text = self.tblViewer.getItem()
        print(text)
  • 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-11T19:06:21+00:00Added an answer on June 11, 2026 at 7:06 pm

    and when a new column is selected within the same row nothing happens.

    That’s because you are using currentRowChanged signal. That signal won’t be fired if you select a column in the same row. You should use currentChanged signal. (and, you should use new style connections)

    And, if you are after just the data, you don’t need those stuff to get the non-proxy QModelIndex and then ask the model, etc. A QModelIndex has a convenience method .data that is just for this purpose. Besides, the signal will send you the selected index, you don’t need extra work for that. This makes your code as simple as this: (note: getItem method is not needed)

    class MainWindow(QtGui.QMainWindow):
        def __init__(self, parent=None):
            #initialize TableViewer
            self.tblViewer.tv.selectionModel().currentChanged.connect(self.tblItemChanged)
    
        def tblItemChanged(self, current, previous):
            '''display text of selected item '''
            # `data` defaults to DisplayRole, e.g. the text that is displayed
            print(current.data().toString()) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters

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.