1

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.

Qt Designer

This is what the resulting window looks like. There are no outlines around the tabs, and the tabs are not clickable:

Resulting window

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
Shock-o-lot
  • 135
  • 1
  • 1
  • 11
  • provide a [mre], try with: `app.setStyle("fusion")` – eyllanesc Nov 14 '19 at 00:40
  • @eyllanesc added. Also app.setStyle("fusion") doesn't seem to do anything. – Shock-o-lot Nov 14 '19 at 00:53
  • @Shock-o-lot Try calling `QApplication.setStyle('fusion')` before creating `app`. – ekhumoro Nov 14 '19 at 14:56
  • @ekhumoro I tried that, but it didn't do anything. – Shock-o-lot Nov 14 '19 at 18:07
  • @eyllanesc The tabs are clickable to change tabs, but there is no visual feedback on the tabs themselves. If I setStyle('Windows''), then the tabs look a lot better, however the tab above the one selected gets highlighted rather than the one selected. I don't, however, want to use Windows theme in my application. – Shock-o-lot Nov 14 '19 at 19:47

0 Answers0