Reputation: 25
I have a QtabWidget and I made a ListWidget inside that tabwidget
self.tabWidget = QtGui.QTabWidget(self.centralwidget)
self.listWidget = QtGui.QListWidget(self.tabWidget)
Then I made a tab:
self.tab1 = QtGui.QWidget()
self.tabWidget.addTab(self.tab1,"hi")
What I'm trying to do is get the listview for inside QTabWidget for tab1.
print self.tabWidget.currentWidget()
It prints out a pointer: PySide.QtGui.QWidget object at 0x0000000004EA84A4 I want the QListWidget so I can call functions like addItem etc.
Edit: I also have another question. I'm using Pyside and theres a function called retranslateUI and setupUI. I want to add a signal for my QTabWidget,
self.tabWidget.currentChanged.connect(self.showStreamList(self.tabWidget.tabText(self.tabWidget.currentIndex())))
but I'm not sure where to put it. I'm putting it in retranslateUI because thats there button.clicked.connects are but when I run the program, I think it executes this command first. The GUI doesn't even display. In general, where should I group these signals/event listeners?
Upvotes: 1
Views: 3422
Reputation: 1388
Taking your comment into account, you seem to want to dynamically add QListWidgets to a QTabWidget and want individual access to each QListWidget.
QTabWidget's addTab() method takes a QWidget and a string as its arguments. A QListWidget, as the name implies, is derived / subclassed from QWidget. Therefore, the addTab()
method will accept a QListWidget, if you pass it one. So self.tabWidget.addTab(self.listWidget,"hi")
should work just fine.
Next, accessing them. QTabWidget has a method to access any tab by its index, sensibly called widget(index)
. Therefore, if you want to access the n
-th widget, you can get it by calling self.tabWidget.widget(n)
.
You could therefore get any list widget and do stuff with it:
lw = self.tabWidget.widget(0) # get the 0th widget
lw.addItem(...)
Upvotes: 2