#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    1
    Rep Power
    0

    Can't Grab Dynamic Form Object - PyQt


    Ok,

    Im sure there is a simple solution to this problem as I am relativeily new to qt.
    I have created a onclick event method that will populate a QTable with a number of values it also populates two of the cells with new objects a button and a QProgressBar, this is all fine except when latter on down the track when I wish to access these objects again. I have named the objects as so

    progressBarName = "progress" + str(row)
    self.progressBar = QProgressBar(self, str(progressBarName))

    and I could grab the object reference from self.progressBar unless I populate more than one row in which I lose it. I have tried using eval and getattr or striaght hard coding to test

    ie
    eval("self.progress0")
    getattr(self, "progress0")
    self.progress0

    but I get errors for all, is there a way of referencing, evaluating an form object by name??

    Thanks in advance

    Dave
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Regensburg, Germany
    Posts
    147
    Rep Power
    16
    What about using a list of progress bars like this:

    somewhere in the __init__ method:
    Code:
    self.progressBar = []
    and during population of the table and with the assumption that "row" is numeric:
    Code:
    progressBarName = "progress" + str(row)
    self.progressBar[row] = QProgressBar(self, progressBarName)
    Now you can access all progress bars by row number:
    Code:
    self.progressBar[row].some_method(some_parameter)
    Or a more general approach if you want to have access to all objects inserted into the table:

    In the __init__ method:
    Code:
    self.tableObjects = []
    ... and during population:
    Code:
    progress_bar = QProgressBar(self, progressBarName)
    button = ...
    another_object = ...
    self.tableObjects[row] = [progress_bar, button, another_object]
    The row objects can then be retrieved by row number like this:
    Code:
    progress_bar, button, another_object = self.tableObjects[row]

IMN logo majestic logo threadwatch logo seochat tools logo