1

I'm writing a GUI with PyQt5; it's supposed to be a main window with multiple tabs. In a part of my code that hides/shows a given tab, I encounter the following error:

AttributeError: 'QTabWidget' object has no attribute 'setTabVisible'

According to the documentation (and when my code worked a few months ago), QTabWidget should have a function called setTabVisible(): https://doc.qt.io/qt-5/qtabwidget.html#setTabVisible

I see in the documentation that this function was introduced in Qt 5.15.

I'm using Spyder 4.1.5, and according to Spyder's "About" window, I'm using:

Python 3.8.5 64-bit | Qt 5.9.7 | PyQt5 5.9.2 | Windows 10

When I use pip freeze to check my version of PyQt5-Qt, though, it's 5.15.3.

After checking other stackoverflow questions and experimenting in Anaconda, I've learned Spyder 4.1.5 requires I use a PyQt version < 5.13, so I'm guessing Spyder has some random older version of PyQt that it replaces mine with so it can run (correct me if I'm wrong).

So my question is: What can I do to be able to use this function (I'm almost sure there's a way, because somehow my code compiled in Spyder last summer, and I don't know what's changed)? And if there isn't a way to use setTabVisible() to hide/show tabs, how can I work around it?

Minimal reproducible example below:

import sys
from PyQt5.QtWidgets import QWidget, QTabWidget, QApplication

app = QApplication(sys.argv)

tabs = QTabWidget()

tabs.addTab(QWidget(),"tab1")
tabs.addTab(QWidget(),"tab2")

tabs.setTabText(1, "test")
tabs.setTabVisible(0, 0)
#print(tabs.isTabVisible(0))


tabs.show()

app.exec_()

QTabWidget.isTabVisible() has the same issue as setTabVisible(). I included it commented out in the code above, but I get this error if I uncomment it:

AttributeError: 'QTabWidget' object has no attribute 'isTabVisible'

I included QTabWidget.setTabText() as an example of a function that's working fine. It seems like my problem's only isolated to setTabVisible() and isTabVisible().

If this is happening on only my computer, and it works fine on yours, can you tell me what I might've done that caused it, and how I might be able to fix it?

If it doesn't work on yours either, do you know how it can be fixed, or if not, how I can work around it?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • If you cannot use Qt5.15, then the only *easy* option is to use `removeTab()` and `insertTab()`, assuming you're not using movable tabs. – musicamante Feb 26 '21 at 02:59

0 Answers0