[PyQt] Tab labels not shown correctly

Davide Liessi davide.liessi at gmail.com
Mon Mar 9 08:45:48 GMT 2020


Hello.
Please consider this example:

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QMainWindow, QVBoxLayout, QWidget,
QApplication, QTabBar)
from PyQt5.QtGui import QIcon

qApp = QApplication([])
win = QMainWindow()

win.tabBar = QTabBar(win)
win.tabBar.setExpanding(False)
win.tabBar.setElideMode(Qt.ElideNone)
win.tabBar.setTabsClosable(True)
win.tabBar.addTab(QIcon('text-plain.svg'), 'Untitled')

layout = QVBoxLayout()
layout.addWidget(win.tabBar)

mainwidget = QWidget()
win.setCentralWidget(mainwidget)
mainwidget.setLayout(layout)

win.show()
qApp.exec_()

To test it, you can get the file text-plain.svg from
https://github.com/frescobaldi/frescobaldi/tree/master/frescobaldi_app/icons/TangoExt/scalable
and put it in the same directory as the script.

The script displays the window in the attached qt5.png.
With (Py)Qt4 it used to display the window in qt4.png.

In particular, observe that
- the text is cut, hiding approximately the first and the last letters,
- there is too much space between the cross and the icon,
- there appears to be the same amount of space at the two sides of the
text (ignoring the cross and the icon), resulting in too much space
from the text to the right margin.

Removing either the icon or the cross (commenting the setTabClosable
line) results in the text being shown entirely, but there is still too
much space after the text.

Am I doing something wrong?
How can I solve these problems?

Best wishes.
Davide


More information about the PyQt mailing list