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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:32:05+00:00 2026-05-26T03:32:05+00:00

i have the following code defining the gui of my app class Ui (object):

  • 0

i have the following code defining the gui of my app

class Ui (object):
    def setupUi():
        self.tableName = QtGui.QTableWidget(self.layoutWidget_20)
        self.tableName.setObjectName(_fromUtf8("twHistoricoDisciplinas"))
        self.tableName.setColumnCount(4)
        self.tableName.setRowCount(3)

and the following code in my app

class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        self.ui = Ui()
        self.ui.setupUi(self)
        self.createtable()

    #creating a tw cell
    def cell(self,var=""):
            item = QtGui.QTableWidgetItem()
            item.setText(var)
            return item

    def createtable(self):
         rows = self.tableName.rowCount()
         columns = self.tableName.columnCount()
         for i in range(rows):
             for j in range(columns):
                 item = self.cell("text")
                 self.ui.tableName.setItem(i, j, item)

I want to be able to add new rows and columns and edit them but i want to lock some of the cells. ( i already have code that expand the table )
how can i make some cells read only while keeping the others read write?
i found this link How to make a column in QTableWidget read only? with a solution for the problem in C++, is python solution similar ?

EDIT: Removed the answer from the post and pasted as an answer

  • 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-05-26T03:32:05+00:00Added an answer on May 26, 2026 at 3:32 am

    I played a little with the code and read some more documentation
    the answer to the problem is

    def createtable(self):
         rows = self.tableName.rowCount()
         columns = self.tableName.columnCount()
         for i in range(rows):
             for j in range(columns):
                 item = self.cell("text")
                 # execute the line below to every item you need locked
                 item.setFlags(QtCore.Qt.ItemIsEnabled)
                 self.ui.tableName.setItem(i, j, item)
    

    The solution is the line “item.setFlags(QtCore.Qt.ItemIsEnabled)”, you use it to set the cell property QtCore.Qt.ItemIsEnabled to disabled, so you can’t select or edit the cell

    You can change a number of other properties this way at runtime as per documentarion on http://doc.qt.io/archives/qt-4.8/qt.html under the section Qt::ItemFlag

    as mentioned in a comment by Sven on the second answer to this question, if you have a static number of rows and columns in your QTableWidgetItem you can select the properties of the cells with Qtdesigner if you use it to create the screens for your application

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

Sidebar

Related Questions

I have some questions regarding the following code: 1 class Test(object): 2 def __init__(self):
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
I have following code class User attr_accessor :name end u = User.new u.name =
I have following code snippet that i use to compile class at the run
I have the following code defining a Functor template and the function running_op, which
Let's say we have the following piece of code: public class Event { }
I have the following code, with the intention of defining and using a list
I have the following code: funcs = [] for i in range(10): def func():
I have following class in android, where I am defining some functions to calculate
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.