[PyKDE] Using QScrollView to manage a changing list of widgets
Jonathan Gardner
jgardn at alumni.washington.edu
Tue Feb 18 02:38:00 GMT 2003
I'm working on some software for a client here, and I've been thinking of
several ways to handle a situation that has come up more than once.
A single patient can have several insurance companies they are subscribed to.
Not just the insurances that are current, but previous insurances as well.
Most common is only one, but having two or three is very common.
One idea I came up with was using QScrollView. It would have only one child
-- a QVBox. This is similar to the first method of using it mentioned in the
Qt documentation.
That QVBox would have the list of patient insurance widgets.The patient
insurance list needs to be able to grow and shrink (as I add or remove
insurance companies) or disappear altogether and be repopulated (when I
switch what patient I am looking at).
I implemented something that just lists QLabels rather than patient insurance
widgets.
One more note: The insurance list is just one tab among many on the main
widget.
class Insurance_Tab(QWidget):
def __init__(self, parent=None, name=None, fl=0):
QWidget.__init__(self, parent, name, fl)
lo = QVBoxLayout(self,0,6)
self.sv = QScrollView(self, "Insurance_Tab_ScrollView")
self.sv.setHScrollBarMode(QScrollView.AlwaysOff)
self.vbox = QVBox(self.sv.viewport())
self.sv.addChild(self.vbox)
lo.addWidget(self.sv)
def set_patient(self, patient):
self.sv.removeChild(self.vbox)
del self.vbox
self.vbox = QVBox(self.sv.viewport())
if patient:
sql = """
SELECT object_id
FROM c_patient_insurance
WHERE patient=%d
""" % patient.object_id
for i in db.query(sql).dictresult():
print i
QLabel(str(i['object_id']), self.vbox)
Anyways, it works fine as long as I am looking at a different tab as I change
the patient. If I am looking at it, it clears, but won't show what has been
added.
Any pointers would be great. Thanks in advance.
--
Jonathan Gardner
jgardn at alumni.washington.edu
Python Qt perl apache and linux
More information about the PyQt
mailing list