How to get usesScrollButtons buttons to scroll tabs when it has many tabs For MAC?
-
Hi,
What version of Qt are you using ?
On what version of macOS ?Can you provide a minimal compilable example that shows that behaviour ?
-
I think that this is because the style does not support it, so if you are using the macOS style you won't get the buttons. Try running your application with -style fusion and then it should show up.
-
@SGaist Thank you for taking interest in my question.
I am using Qt 5.11.0 and MacOS version is 10.13.5.
Here I put separate function using QTabBar.
QWidget* TestClass::getwidget(){ static QWidget *w = 0; if (w) { return w; } w = new QWidget(); auto *lay = (new QVBoxLayout(w)); lay->setContentsMargins(0,0,0,0); lay->setSpacing(0); QPushButton *addNewButton = nullptr; QPushButton *tileButton = nullptr; QTabBar *tabBar = nullptr; QFrame *tabFrame = new QFrame(); auto *tabFrameLay = new QHBoxLayout(tabFrame); tabFrameLay->setContentsMargins(0,0,0,0); tabFrameLay->setSpacing(0); tabFrameLay->addWidget(tabBar = new QTabBar); tabFrameLay->addWidget(addNewButton = new QPushButton("+")); tabFrameLay->addStretch(1); tabFrameLay->addWidget(tileButton = new QPushButton("View All Graphs")); lay->addWidget(tabFrame); tabBar->setExpanding(false); tabBar->setMovable(true); //tabBar->setUsesScrollButtons(true); static int tabIndex = 0; QObject::connect(addNewButton, &QPushButton::clicked, [=]() { tabBar->insertTab(tabIndex, "---------------TabName----123456789"); tabBar->setCurrentIndex(tabIndex); tabIndex++; }); return w; }
Pic from windows
pic from MAC
-
@Yash001 I suggest you have a look at http://doc.qt.io/qt-5/qstyle.html as this will give more details. But the quick version is to just start your application with the "-style fusion" arguments.
-
Hi @AndyS,
I am still stuck in same issue, as per your guideline, and from reading documents.
The style of the entire application can be set using the QApplication::setStyle() function. It can also be specified by the user of the application, using the -style command-line option:
I create my own style for QToolButton with help
GUI.css
file, and I applied to application with help ofApplyStyle()
function.I am calling
ApplyStyle()
function is from constructor.ApplyStyle() function definition.
void MainWindow::ApplyStyle() { QFile f("./GUI.css"); if(!f.open(QIODevice::ReadOnly)) return; QString newStyleSheet = f.readAll(); qobject_cast<QApplication *>(QApplication::instance())->setStyleSheet(newStyleSheet); f.close(); }
GUI.css file.
QTabBar QToolButton { /* the scroll buttons are tool buttons */ background:light yellow; } QTabBar QToolButton::right-arrow { /* the arrow mark in the tool buttons */ border:5px solid red; } QTabBar QToolButton::left-arrow { border:5px solid green; }
Still Mac System does not recognized the usesScrollButtons.
I checked ```tabbar->usesScrollButtons();``, and It is return false on Mac.
-
That's because the macOS style doesn't implement them. As stated in the QTabBar documentation:
By default the value is style dependant.
. It's not a bug it's a platform guideline. Just check with Safari, open lots of tabs. You won't see any scroll button. -
Thank You @SGaist and @AndyS. I am able to get QToolButton of QTabBar by applying Fusion style.
I applied Fusion Style By:
#include "mainwindow.h" #include <QTimer> #include <QtGlobal> #include <QFile> #include <QLocale> #include <QSplashScreen> #include <QGuiApplication> #include <qstylefactory.h> int main(int argc, char *argv[]) { QLocale::setDefault(QLocale::system()); QApplication a(argc, argv); a.setStyle(QStyleFactory::create("Fusion")); MainWindow w; w.showMaximized(); return a.exec(); }