[PyQt] QTabWidget

kib2 kib2 at free.fr
Sun Nov 25 23:16:03 GMT 2007


Lawrence Shafer a écrit :
> Let me explain things better here. I could easily do this if I was hand 
> coding the whole thing, but I've done the ui in QT Designer, so that's 
> where I'm stumped. I have a Qwidget with everything in it, so how do I 
> add the same qwidget to each tab with a different prefix on each widget 
> based on the tab name? I seem to remember something about this from 
> months past, but cannot dig it up.
> 
> Lawrence Shafer wrote:

I've made something like this for my app:

class Myapp(QtGui.QMainWindow, Ui_Foo):
     def __init__(self):
         QtGui.QMainWindow.__init__(self)
         Ui_Foo.__init__(self)

         ## TABS MANAGEMENT
         self.tabnumber = 0
         self.tabs = []
         self.current_tab = 0

     def addNewTab(self):
         if self.tabnumber != 0 :
             tab = QtGui.QWidget()
             tab.setObjectName("tab%s"%(self.tabnumber))
         else: # self.tab_id = 0
             tab = self.tab # the tab you construct in designer

         # build a new BarFrame with
         hboxlayout = QtGui.QHBoxLayout(tab)
         hboxlayout.setObjectName("hbox%s"%(self.tabnumber))
         qef = BarFrame(tab)
         qef.setObjectName("barframe%s"%(self.tabnumber))
         hboxlayout.addWidget(qef)

         self.tabs.append(tab)
	# add to tabWidget
         self.tabWidget_files.addTab(tab, "BarFrame %s*"%self.tabnumber)
         self.tabWidget_files.setCurrentWidget(tab) # get the focus

         self.tabnumber += 1

Maybe it can help you ?
Cheers.


More information about the PyQt mailing list