3

I can't see the close button on individual tabs when using PyQt5. I can close the individual tabs when I click where I know the close button should be, but can't see the button outright:

#!/bin/python3
import sys
from PyQt5.QtWidgets import (QApplication, QVBoxLayout,
                            QTabBar, QFrame)

class App(QFrame):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Web Browser")
        self.setBaseSize(683, 384)
        self.CreateApp()

    def CreateApp(self):
        self.layout = QVBoxLayout()
        self.tab_Bar = QTabBar(movable=True, tabsClosable=True)
        self.tab_Bar.tabCloseRequested.connect(self.CloseTab)

        self.tab_Bar.addTab("Tab 1")
        self.tab_Bar.addTab("Tab 2")

        self.tab_Bar.setCurrentIndex(0)

        self.layout.addWidget(self.tab_Bar)
        self.setLayout(self.layout)
        self.show()

    def CloseTab(self, i):
        self.tab_Bar.removeTab(i)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = App()

    sys.exit(app.exec_())

I'm using Python version 3.6.2 and PyQt5 version 5.9

Anonta
  • 2,500
  • 2
  • 15
  • 25
Jon E
  • 99
  • 7
  • I cannot reproduce the problem on linux. What platform are you on, and what widget style are you using? – ekhumoro Sep 07 '17 at 20:28
  • I'm on OS X 10.11.6, I'm using the QTabBar widget (second line of CreateApp function) if that is what your asking. If it's something else, how can I find out? – Jon E Sep 07 '17 at 20:31
  • As an experiment, try putting the line `QApplication.setStyle('Fusion')` before `app = QApplication(sys.argv)`. – ekhumoro Sep 07 '17 at 22:04
  • That was cool, it put ninja-esque close buttons on the right side of each tab, and without the setStyle, I put 'print(app.style())' after 'window=App()' which returned '' – Jon E Sep 07 '17 at 22:26
  • What is the output of `print(QtWidgets.QStyleFactory.keys())`? Try setting each of the styles to see if it makes any difference. You could also try setting your own icon using the stylesheet shown [here](https://stackoverflow.com/a/2032326/984421). This should at least determine whether the tabs can show icons on your system. – ekhumoro Sep 07 '17 at 23:58
  • The print command outputted a 3-element list: `['Windows', 'Fusion', 'Macintosh']` and after trying all three, `Windows` and `Fusion` both produce icons, however `Macintosh` does not. BUT setting up my own icon using a stylesheet worked – Jon E Sep 08 '17 at 00:20
  • 1
    Huh. Looks like a bug in the Mac style, then. And here it is: [QTBUG-61092](https://bugreports.qt.io/browse/QTBUG-61092). Seems to have been fixed in Qt-5.9.2. – ekhumoro Sep 08 '17 at 01:05

0 Answers0