Re: Tab labels not shown correctly

Davide Liessi <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <CAOXn3brVb0-Oe4ffh1mM_Q51nOJD-QNDnPAUZY1hJ5v9ZOD8VQ@mail.gmail.com>
Il giorno lun 9 mar 2020 alle ore 13:27 Souvik Dutta
<[email protected]> ha scritto:
> Did you use the correct selector like you should probably say,
> self.setStyleSheet(<object name>: disabled{padding: 0px 0px 0px 0px})

I started from the examples in
https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar
and with the help of
https://doc.qt.io/qt-5/stylesheet-reference.html
I arrived at the example below, which reproduces quite well the
default style on Mac, while also fixing the display of the text in the
tabs.

Thanks for your help!
Best wishes.
Davide

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')
win.tabBar.addTab(QIcon('text-plain.svg'), 'Untitled 2')
win.tabBar.addTab(QIcon('text-plain.svg'), 'Untitled 3')
win.tabBar.addTab(QIcon('text-plain.svg'), 'Untitled 4')
win.tabBar.addTab(QIcon('text-plain.svg'), 'Untitled 5')

style = """
QTabBar::tab {
    background: white;
    border-style: solid;
    border-width: 1px 0px;
    border-color: #ACACAC;
    min-width: 8ex;
    padding: 2px 4px 2px 2px;
}

QTabBar::tab:selected:active {
    border-color: #045FFF;
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                stop: 0 #69B1FA, stop: 1 #0C80FF);
    color: white;
}

QTabBar::tab:selected:!active {
    border-color: #ACACAC;
    background: #E5E5E5;
}

QTabBar::tab:first {
    border-left-width: 1px;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

QTabBar::tab:!first:!selected:!previous-selected {
    border-left-color: #E5E5E5;
    border-left-width: 1px;
}

QTabBar::tab:last {
    border-right-width: 1px;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}
"""

win.tabBar.setStyleSheet(style)

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

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

win.show()
qApp.exec_()
_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.