0

Please tell me why there is a distance between the QTabBar scroller buttons with a small width of the scroller buttons and how can this be fixed?

enter image description here

In this case, I have the following in the style sheet:

QTabBar::scroller {
    width: 6px;
}

At the same time, the whole paradox is that in a pure example there is no distance between the buttons and I can't understand how this could have gone wrong in my example. Even the type of this indentation is unclear: it is neither a widget neither a layout, it is not clear what kind of object it is.

Helg1980
  • 47
  • 1
  • 9

2 Answers2

1

Try this? distance between the QTabBar scroller buttons can be set using QProxyStyle::pixelMetric

#include "QtWidgetsApplication1.h"
#include <QtWidgets/QApplication>
#include<string>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<QElapsedTimer>
#include<QThread>
#include<QTimer>
#include<QSerialPort>
#include<QTextStream>
#include<QTreeWidget>
#include<QTreeWidgetItem>
#include<QQuickView>
#include<QQmlEngine>
#include<QQmlContext>
#include<QTimer>
#include<iostream>
using namespace std;
#include<QTabBar>
#include <QProxyStyle>

class MyProxyStyle : public QProxyStyle
{
public:
    int pixelMetric(QStyle::PixelMetric metric, const QStyleOption* option = nullptr, const QWidget* widget = nullptr) const override
    {
        if (metric == QStyle::PM_TabBar_ScrollButtonOverlap)
        {
            return -50;
        }
        return QProxyStyle::pixelMetric(metric, option, widget);
    }
};
int main(int argc,char*argv[]) {
    QApplication a(argc, argv);
    a.setStyle(new MyProxyStyle);
    QTabBar bar;
    bar.setMaximumWidth(300);
    bar.setStyleSheet("QTabBar::scroller { width: 100px;}");
    bar.addTab("one");
    bar.addTab("two");
    bar.addTab("threee");
    bar.addTab("aaaaaaaa");
    bar.addTab("bbbbbbbbbbbbb");
    bar.addTab("cccccccccccc");
    bar.addTab("dddd");
    bar.show();
    return a.exec();
}

kenash0625
  • 657
  • 3
  • 8
0

It's because of an outdated version of Qt.

Helg1980
  • 47
  • 1
  • 9