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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:22:10+00:00 2026-06-11T10:22:10+00:00

User sets values manually in all cells in a QTableWidget. The values of the

  • 0

User sets values manually in all cells in a QTableWidget. The values of the first row of the table represent the values we want to store in a dictionary FirstRowDict. Second row values will be put in SecondRowDict and so on.

enter image description here

So from a table like one shown in the picture,
we want to end up in this example with FirstRowDict={0:10,1:20}
and SecondRowDict={0:30,1:40}

To achieve this i created a button and added an action that updates the target dictionaries when clicked:

def button_click():
    for j in range(0,2):
        FirstRowDict.update({i: float(str(tablewidget.itemAt(0,j).text()))})

        #I put "0" in itemAt because first row is zero
        #tablewidget = QTableWidget() declared earlier in the source code

        SecondRowDict.update({i: float(str(tablewidget.itemAt(1,j).text()))})

    print '1st_Row_Dict=%s'%1st_Row_Dict,'\n2nd_Row_Dict=%s'%2nd_Row_Dict

The output is not correct since the dictionaries are populated with same value and not the unique value of each cell.
I get FirstRowDict={0:10,1:10} and SecondRowDict={0:10,1:10}

It seems that i have to create a new item using QTableWidgetItem http://doc.qt.nokia.com/4.7-snapshot/qtablewidget.html#item

Python begginer, some advice would be appreciated.

  • 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-11T10:22:11+00:00Added an answer on June 11, 2026 at 10:22 am

    Ah, I see the confusion. itemAt returns the item at the given position, but it’s not row/column. It’s the coordinate (think of it as pixel).

    Yes, you should use item instead of itemAt.

    You don’t need a str if you’re going to convert it to float. float() will work on a QString as if it was a str. And, instead of .update, you can just assign the new value to the key.

    FirstRowDict[i] = float(tablewidget.item(0, j).text())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do the following: The user sets 3 parameters in MVC3 view:
I've got small CSV file with data. I want all variables in a row
When the user sets the focus to an edit control on my HTML page,
I am working on an app where the user sets something (not important what
I have made Catifier.com recently, and once the user sets their own background image,
I'm trying to find a way to set a cookie that sets a user's
I have a button which when pressed, sets the user's rights in the db.
I have a view that sets its hidden when the user taps the main
I've got a user log in form which sets a cookie and enables members
Meaning: A user auth's to an application -> application sets the namespace of the

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.