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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:59:59+00:00 2026-06-08T20:59:59+00:00

The purpose of this code is to show a list of string with a

  • 0

The purpose of this code is to show a list of string with a model herited from QtCore.QAbstractListModel

import sys
from PyQt4 import QtGui, QtCore

class StringListModel(QtCore.QAbstractListModel):
    def __init__(self, strings):
        QtCore.QAbstractListModel.__init__(self)
        self._string_list = strings
    def rowCount(self):
        return len(self._string_list)
    def data(self, index, role):
        if not index.isValid() : return QtCore.QVariant()
        if role != QtCore.Qt.DisplayRole : return QtCore.QVariant()
        if index.row() <= self.rowCount() : return QtCore.QVariant()
        return QtCore.QVariant(self._string_list[index.row()])
    def headerData(self, section, orientation, role = QtCore.Qt.DisplayRole):
        if role != QtCore.Qt.DisplayRole : return QtCore.QVariant()
        if orientation == QtCore.Qt.Horizontal : return QtCore.QVariant("Column %s"%section)
        else:
            return QtCore.QVariant("Row %s"%section)

if __name__ == '__main__':
    a = QtGui.QApplication(sys.argv)
    lines = ["item 1", "item 2", "item 3"]
    model = StringListModel(lines)
    view = QtGui.QListView()
    view.setModel(model)
    view.setWindowTitle("String list model")
    view.show()
    a.exec_()

The error I’ve got is

TypeError: rowCount() takes exactly 1 positional argument (2 given)

  • 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-08T21:00:02+00:00Added an answer on June 8, 2026 at 9:00 pm

    The problem is that QAbstractItemModel.rowCount takes a ‘parent’ parameter. The following tweak suppresses the error (though I don’t know if it actually implements the correct logic)

    def rowCount(self, parent=None):
        return len(self._string_list)
    

    Also, are you sure that QListWidget doesn’t provide the functionality you need?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The purpose of this code is to pull upgrade.zip from a central server, extract
This is an example of code for simple system tray PyQt application. import sys
Quick question, What have I done wrong here. The purpose of this code is
What is the purpose of these java.lang.annotation imports in this code? Why are they
The purpose of the page is to show a list of jobs. The form
I have this PHP class, whose purpose is to fetch some configuration data from
When I use this code to download this image (only used for testing purposes),
I have this block of code where when I hover (click for purposes of
I'm looking through some code for learning purposes. I'm working through this portion of
[purpose] This simple command sequence runs expected in the Windows' CMD shell: dir &

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.