0

I'm new to Python and trying to use PyQt6 QTabsWidget. I have problems with setting the tabs to West. By the documentation the following code should work but PyCharm just gives me AttributeError: type object 'QTabWidget' has no attribute 'West' even though the official documentation says it should have that attribute. I've also seen this one in every guide and tutorial about QTabWidget.

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle('MyApp')

        tabs = QTabWidget()
        tabs.setTabPosition(QTabWidget.West)
        tabs.setMovable(True)

By looking into the QtWidgets.pyi file I found some functions inside the class definition of QTabWidget. Using those I got the following code that works.

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle('MyApp')

        tabs = QTabWidget()
        tabs.setTabPosition(QTabWidget.TabPosition(2))
        tabs.setMovable(True)

Why isn't the first one working?

musicamante
  • 41,230
  • 6
  • 33
  • 58
unown
  • 1
  • 2
  • With PyQt6 all enum flags require the explicit enum name. Change to `tabs.setTabPosition(QTabWidget.TabPosition.West)`. Note: while they generally match, PySide and PyQt can have slightly different behaviors, so you cannot always rely on the documentation of one while using the other. Also, if you're using Qt6, you should use the related documentation. – musicamante Feb 21 '22 at 22:33
  • Yes, that worked. I used the search function on their page and thought it would just take me straight to the newest version. I have to be more careful with the documentation in the future. Thanks for the help! – unown Feb 21 '22 at 22:59
  • You're welcome. Please don't edit a question to add the answer, the comment and duplicate link is enough. Questions should never include answers, as there is the answer field for those (unless questions are closed, like in your case). Please review more carefully the [tour] (and also check [ask] and [answer]). – musicamante Feb 21 '22 at 23:03

0 Answers0