Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get usesScrollButtons buttons to scroll tabs when it has many tabs For MAC?

How to get usesScrollButtons buttons to scroll tabs when it has many tabs For MAC?

Scheduled Pinned Locked Moved Solved General and Desktop
qtabbarmacosqscrollbarqtabwidget
11 Posts 3 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yash001
    wrote on last edited by Yash001
    #1

    Hello,
    I am using QTabBar in my application. I would use the QTabBar::usesScrollButtons for many tab. I am getting usesScrollButtons in windows OS.

    take screenshot from Windows OS.

    0_1536873363713_7a913be4-b3f1-489b-925a-ffc20caa6a3a-image.png

    But Whenever I tried same code in MAC system. At that time I am getting like below pic.

    0_1536873299425_67113e52-eddf-430f-85de-a6a34ead75cd-image.png

    I tried setUsesScrollButtons(true) but i did not get any change in Mac System.

    am I missing any step for MAC system?

    MinimumWidthTabBar .h file

    class MinimumWidthTabBar : public QTabBar {
    public:
    	MinimumWidthTabBar(QWidget *parent = 0);
    
    	QSize minimumSizeHint() const Q_DECL_OVERRIDE;
    };
    

    MinimumWidthTabBar.cpp file

    #include "MinimumWidthTabBar.h"
    
    MinimumWidthTabBar::MinimumWidthTabBar(QWidget *parent) : 
    	QTabBar(parent)
    {
    }
    QSize MinimumWidthTabBar::minimumSizeHint() const {
    	return sizeHint();
    }
    

    use MinimumWidthTabBar in function

    static QWidget *w = 0;
    	
    	if (w) {
    		return w;
    	}
    
    	// create New Object and give a name "new-data-window-owner"
    	w = OBJ_NAME(WDG(), "new-data-window-owner");
    	
    	// create vertical layout
    	auto *lay = NO_SPACING(NO_MARGIN(new QVBoxLayout(w)));
    	
    	// create pointer for Pushbutton "+" and Tile button
    	QPushButton *addNewButton = nullptr;
    	QPushButton *tileButton = nullptr;
    	
    	QTabBar *tabBar = nullptr;
    
    	
    	auto stackedLayWdg = OBJ_NAME(WDG(), "new-data-window-placeholder");
    	
    
    	auto stackedLayWdgLay = NO_SPACING(NO_MARGIN(new QHBoxLayout(stackedLayWdg)));
    	auto mdiArea = new QMdiArea;
    	
    	mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    	mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    	
    	m_ui.newDataTab.mdiArea = mdiArea;
    	stackedLayWdgLay->addWidget(mdiArea);
    	
    	//create new frame for data window 
    	QFrame *tabFrame = OBJ_NAME(new QFrame, "builder-tab-frame");
    	auto *tabFrameLay = NO_SPACING(NO_MARGIN(new QHBoxLayout(tabFrame)));
    	
    
    	// create tab into tab bar
    	tabFrameLay->addWidget(tabBar = OBJ_NAME(new MinimumWidthTabBar, "new-data-window-tab"));
    	tabFrameLay->addWidget(addNewButton = OBJ_NAME(PBT("+"), "builder-tab-add-new"));
    	tabFrameLay->addStretch(1);
    	tabFrameLay->addWidget(tileButton = OBJ_NAME(PBT("View All Graphs"), "builder-tab-mdi"));
    
    	m_ui.newDataTab.tabBar = tabBar;
    	
    	lay->addWidget(tabFrame);
    	lay->addWidget(stackedLayWdg);
    	
    
    	tabBar->setExpanding(false);
    	tabBar->setMovable(true);
    
    
    auto UpdateTabAndCustomFrame = [=](const QUuid id, ExperimentType type, QWidget* customFrame, const QString tabName, const int tabIndex, bool isExperimentRun) {
    
    		tabBar->insertTab(tabIndex, tabName);
    		tabBar->setCurrentIndex(tabIndex);
    		
    	};
    
    m_connections << QObject::connect(addNewButton, &QPushButton::clicked, [=]() {
    		MainWindow::CsvFileData csvData;
    		if (!m_mainWindow->ReadCsvFile(m_mainWindow, csvData)) {
    			return;
    		}
    		
    		// when we Pressed "+" button at that time tab will be shown into tabHeaderLay
    		if (tabBar->isHidden()) {
    			tabBar->show();
    		}
    
    		// print the name into tab bar
    		QString tabName = csvData.fileName;
    		
    		// craete Uniq ID for for Window
    		const QUuid id = QUuid::createUuid();
    
    		auto dataTabWidget = CreateNewDataTabWidget(id,
    			ET_SAVED,
    			tabName,
    			csvData.xAxisList,
    			csvData.yAxisList,
    			csvData.filePath,
    			&csvData.container);
    
    		UpdateTabAndCustomFrame(id, ET_SAVED, dataTabWidget, tabName, tabBar->count(), false);
    
    	
    	});
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt are you using ?
      On what version of macOS ?

      Can you provide a minimal compilable example that shows that behaviour ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Y 1 Reply Last reply
      0
      • AndySA Offline
        AndySA Offline
        AndyS
        Moderators
        wrote on last edited by
        #3

        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.

        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Y 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          What version of Qt are you using ?
          On what version of macOS ?

          Can you provide a minimal compilable example that shows that behaviour ?

          Y Offline
          Y Offline
          Yash001
          wrote on last edited by Yash001
          #4

          @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
          0_1536877801508_9dc39185-701b-41c0-8553-04fc8568bf30-image.png

          pic from MAC
          0_1536877944601_70dc5d51-7e1a-4d60-b456-5e383a297102-image.png

          1 Reply Last reply
          0
          • AndySA AndyS

            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.

            Y Offline
            Y Offline
            Yash001
            wrote on last edited by
            #5

            @AndyS Thank you for direction. I am sorry, May be it is silly question. But I don't about -style fusion. What is -style fusion? How can I use it?

            1 Reply Last reply
            0
            • AndySA Offline
              AndySA Offline
              AndyS
              Moderators
              wrote on last edited by
              #6

              @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.

              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              Y 1 Reply Last reply
              1
              • AndySA AndyS

                @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.

                Y Offline
                Y Offline
                Yash001
                wrote on last edited by Yash001
                #7

                @AndyS Thank you I will go in more detail.

                1 Reply Last reply
                0
                • Y Offline
                  Y Offline
                  Yash001
                  wrote on last edited by Yash001
                  #8

                  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 of ApplyStyle() 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.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    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.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    Y 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      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.

                      Y Offline
                      Y Offline
                      Yash001
                      wrote on last edited by
                      #10

                      @SGaist got it.

                      1 Reply Last reply
                      0
                      • Y Offline
                        Y Offline
                        Yash001
                        wrote on last edited by
                        #11

                        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();
                        }
                        
                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved