Pyqt5: looking for a way to close tabs in QTabWidget

Viewed 55

I'm using pyqt5 with Qt designer now While making my tool for work.

def figTabs(self):
    l1 = QLabel("F Title")
    b1 = QPlainTextEdit("a%d" % (self.Ftab.count() + 1))
    l2 = QLabel("F Caption")
    b2 = QPlainTextEdit("b%d" % (self.Ftab.count() + 1))
    vbox = QVBoxLayout()
    vbox.addWidget(l1)
    vbox.addWidget(b1)
    vbox.addWidget(l2)
    vbox.addWidget(b2)
    tab=QTabWidget()
    tab.setLayout(vbox)
    b1.setObjectName(f"fig_title_%d" % (self.Ftab.count() + 1))
    b2.setObjectName(f"fig_caption_%d" % (self.Ftab.count() + 1)) 
    self.Ftab.addTab(tab,  "Fig %d" % (self.Ftab.count() + 1))
    print(b1.objectName())
    print(b2.objectName()) 
    a = b1.toPlainText()
    print(a)
    #tabs=QTabWidget()
    #self.setTabsClosable(True)
    #tab.setTabsClosable(True)
    #tab.tabCloseRequested.connect(lambda index: tab.removeTab(index))

enter image description here

This one makes a new tab when i cliked connected button with labels and boxes.

In QTabwidget the option tabsClosable is checked in Qt Designer So when I make one it comes up with close button then I tried to close it but didnot work

the tabs needed to be addable and closable with layouts that i added in the code (its because i have trouble in using layout func in Qt Designer) and additionally i can't call that objects even if i set the name for them i need to call them and use the text in them(like usually using toPlainText)

0 Answers
Related