There is QTabWidget with two Tabs: 'A' and 'B'.
And there is a listWidgetA = QtGui.QListWidget() which I want to share among 'A' and 'B'.
So far I was unable to find a way to assign listWidgetA to two different layouts. Assigning it to one layout immediately cancels an assignment to another. I don't want to create another QtGui.QListWidget() since it would produce a lot of duplicate/repetitive code. Here is the example. It would be interesting to know if there is solution to situation like this.
from PyQt4 import QtGui, QtCore
import sys, os
class Dialog_01(QtGui.QMainWindow):
def __init__(self):
super(QtGui.QMainWindow,self).__init__()
myTabWidget = QtGui.QTabWidget()
QGroupBoxA = QtGui.QGroupBox()
QHBoxLayoutA = QtGui.QHBoxLayout()
QGroupBoxA.setLayout(QHBoxLayoutA)
myTabWidget.addTab(QGroupBoxA,' Tab A ')
listWidgetA = QtGui.QListWidget()
for i in range(12):
QtGui.QListWidgetItem( 'Item '+str(i), listWidgetA )
QHBoxLayoutA.addWidget(listWidgetA)
QGroupBoxB = QtGui.QGroupBox()
QHBoxLayoutB = QtGui.QHBoxLayout()
QGroupBoxB.setLayout(QHBoxLayoutB)
# QHBoxLayoutB.addWidget(listWidgetA)
myTabWidget.addTab(QGroupBoxB,' Tab B ')
self.setCentralWidget(myTabWidget)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
dialog_1 = Dialog_01()
dialog_1.show()
dialog_1.resize(480,320)
sys.exit(app.exec_())