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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:29:24+00:00 2026-06-07T05:29:24+00:00

I am working on python plugins.I used PyQt4 Designer. I want to list query

  • 0

I am working on python plugins.I used PyQt4 Designer.
I want to list query result into QTreeWidget.
My code is as follows:

c = self.db.con.cursor()
self.db._exec_sql(c, "select est from bio")
for row in c.fetchall():
    item_value=unicode(row[0])
    top_node1 = QTreeWidgetItem(item_value)
    self.treeWidget.insertTopLevelItem(0, top_node1)

The query returns the values as:

enter image description here

But when i list these values into QTreeWidget using above code,it is shown as below :

enter image description here

Only first character is shown.If i change ‘0’ to some other number in self.treeWidget.insertTopLevelItem(0, top_node1) ,nothing appears in QTreeWidget.

How do i do it????
thanx.

  • 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-07T05:29:25+00:00Added an answer on June 7, 2026 at 5:29 am

    If you take a look at the documentation for a QTreeWidgetItem, you will see there are a number of possible constructors for creating an instance. Though none of which it seems you are using in a way that is going to give you desirable results. The closest match to the signature you are providing is:

    QTreeWidgetItem ( const QStringList & strings, int type = Type )

    What this is probably doing is taking your string (I am assuming row[0] is a string because I don’t know which drivers you are using) and applying it as a sequence, which would fullfill the requiremets of QStringList. Thus what you are getting is populating multiple columns of your item with each letter of your string value. If this is what you wanted, then you would n eed to tell your widget to show more columns: self.treeWidget.setColumnCount(10). But this isn’t what you are looking for I am sure.

    More likely what you should be trying is to create a new item, then add the value to the desired column:

    item = QTreeWidgetItem()
    item.setText(0, unicode(row[0]))
    self.treeWidget.insertTopLevelItem(0, item)
    

    You can use the default constructor with no arguments, set the text value of the first column to your database record field value, and then add that item to the tree. You could also build up a list of the items and add them at once:

    items = []
    for row in c.fetchall():
        item = QTreeWidgetItem()
        item.setText(0, unicode(row[0]))
        items.append(item)
    self.treeWidget.insertTopLevelItems(0, items)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on python plugins.I designed my form using pyqt4 designer. I used
I am working on python plugins.I used PYQT4 designer for the forms. I am
I am working on python plugins.I used QTreeWidget to list items. [listing in qtreewidget][1]
I am working with python plugins.I used list to store some values as below:
I am working with python plugins for qgis.I am using python2.5 and pyqt4 designer.I
I am working with PyQT4 designer and Python 2.5 for python qgis plugins. when
I am working with python plugins for QGIS.I am using python2.5 and pyqt4 .My
I am working with Python plugins. I have my list called station_list ,to which
I am working with python plugins for qgis .I developed the plugin same as
Working with Python in Emacs if I want to add a try/except 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.