I got answer on a different channel, thanks to the guys on #pyqt on freenode. The problem is that QScrollArea
needs a QWidget
set by setWidget()
, and that should contain the QVBoxLayout
.
Here is the fixed code:
while self.tabWidget.widget(0):
self.tabWidget.removeTab(0)
for i in data['tabList']:
self.log("Adding tab: '%s'" % i, DEBUG)
self.data['tabDict'][i]['scrollarea'] = QScrollArea()
self.data['tabDict'][i]['scrollarea'].setWidgetResizable(True)
self.data['tabDict'][i]['widget'] = QWidget()
self.data['tabDict'][i]['vbox'] = QVBoxLayout()
for j in self.data['tabDict'][i]['groupList']:
self.log("Adding group: '%s'" % j, DEBUG)
self.data['tabDict'][i]['groupDict'][j]['groupbox'] = QGroupBox(j)
self.data['tabDict'][i]['groupDict'][j]['formlo'] = QFormLayout()
print self.data['tabDict'][i]['groupDict'][j]['formlo']
for k in self.data['tabDict'][i]['groupDict'][j]['fields']:
self.log("Adding field: '%s'" % k['name'])
k['lineedit'] = QLineEdit(k['value'])
k['lineedit'].setToolTip('<b>Type:</b> %s<br><b>TSDB path:</b> %s<br><b>Line:</b> %d<br><b>Comment:</b> %s' % (k['type'],k['path'],k['row'], k['comment']))
self.data['tabDict'][i]['groupDict'][j]['formlo'].addRow(k['name'], k['lineedit'])
self.data['tabDict'][i]['groupDict'][j]['groupbox'].setLayout(self.data['tabDict'][i]['groupDict'][j]['formlo'])
self.data['tabDict'][i]['vbox'].addWidget(self.data['tabDict'][i]['groupDict'][j]['groupbox'])
self.data['tabDict'][i]['widget'].setLayout(self.data['tabDict'][i]['vbox'])
self.data['tabDict'][i]['scrollarea'].setWidget(self.data['tabDict'][i]['widget'])
self.tabWidget.addTab(self.data['tabDict'][i]['scrollarea'], i)
It is still an open question though that what resulted the weird behavior of the first code. :)