问题
I am trying to use this solution by @eyllanesc:
pyqt qtabwidget horizontal tab and horizontal text in QtDesigner.
My main window has a QStackedWidget in which one of the pages is the page with horizontal tabs. I used Qt designer to create a dialog with a tab widget, and set the tabPosition to West. Then I promoted the TabWidget like shown in the original post.
This is what the resulting window looks like. There are no outlines around the tabs, and the tabs are not clickable:
This is my main code:
import sys
from PySide.QtGui import *
from PySide.QtCore import *
from tabs import TabsUi_Dialog
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.mainMenuWidget = MainStack(self)
self.setCentralWidget(self.mainMenuWidget)
self.show()
class MainStack(QWidget):
def __init__(self,parent=None):
super(MainStack,self).__init__(parent)
self.initUI()
def initUI(self):
layout = QVBoxLayout(self)
self.stack = QStackedWidget(parent=self)
self.tabPage = TabPage()
#Add Pages to Stack
self.stack.addWidget(self.tabPage)
#Add Stack to Layout
self.stack.setCurrentWidget(self.tabPage)
layout.addWidget(self.stack)
class TabPage(QWidget):
def __init__(self,parent=None):
super(TabPage,self).__init__(parent)
self.tabs = TabsUi_Dialog()
self.tabs.setupUi(self)
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWin = MainWindow()
ret = app.exec_()
sys.exit( ret )
And this is the tabs.py file created after converting the Qt Designer UI file with py-uic:
from PySide import QtCore, QtGui
class TabsUi_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.verticalLayout = QtGui.QVBoxLayout(Dialog)
self.verticalLayout.setObjectName("verticalLayout")
self.tabWidget = TabWidget(Dialog)
self.tabWidget.setTabPosition(QtGui.QTabWidget.West)
self.tabWidget.setObjectName("tabWidget")
self.tab = QtGui.QWidget()
self.tab.setObjectName("tab")
self.tabWidget.addTab(self.tab, "")
self.tab_2 = QtGui.QWidget()
self.tab_2.setObjectName("tab_2")
self.tabWidget.addTab(self.tab_2, "")
self.verticalLayout.addWidget(self.tabWidget)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QtGui.QApplication.translate("Dialog", "Tab 1", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QtGui.QApplication.translate("Dialog", "Tab 2", None, QtGui.QApplication.UnicodeUTF8))
from tabwidget import TabWidget
来源:https://stackoverflow.com/questions/58847724/pyside-create-horizontal-tabs-with-horizontal-text