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. Changing cursor in QTabBar
QtWS25 Last Chance

Changing cursor in QTabBar

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 569 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.
  • M Offline
    M Offline
    mimamrafi
    wrote on last edited by
    #1

    Hai everyone. I want to ask. How to change the cursor when the curson in Tab Bar? I try

    ui->tab->setCursor(Qt::PointingHandCursor);
    

    but the cursor change in the whole of tabwidget

    artwawA raven-worxR 2 Replies Last reply
    0
    • M Offline
      M Offline
      mimamrafi
      wrote on last edited by
      #6

      Hey, I solved this problem. This is my last code

      //maingui.h
      #include <QTabBar>
      ...
      private slots:
      ...
          void mouseMoveEvent(QMouseEvent *event);
      
      private:
          QList<QTabBar *> tabBar ;
      

      This is the CPP File

      //maingui.cpp
      MainGUI::MainGUI(QWidget *parent)
          : QDialog(parent, Qt::WindowTitleHint |  Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint),
          ui(new Ui::MainGUI)
      {
          ui->setupUi(this);
          setMouseTracking(true);
      ...
      }
      
      void MainGUI::mouseMoveEvent(QMouseEvent *event){
          tabBar = this->ui->tabWidget->findChildren<QTabBar *>();
          tabBar.at(0)->setCursor(Qt::PointingHandCursor);
      }
      

      But sometimes its not initialize for the first time. Thank you

      1 Reply Last reply
      0
      • M mimamrafi

        Hai everyone. I want to ask. How to change the cursor when the curson in Tab Bar? I try

        ui->tab->setCursor(Qt::PointingHandCursor);
        

        but the cursor change in the whole of tabwidget

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #2

        @mimamrafi I don't think you can without subclassing; there is no header property that would return the tab headers only.

        For more information please re-read.

        Kind Regards,
        Artur

        M 1 Reply Last reply
        0
        • M mimamrafi

          Hai everyone. I want to ask. How to change the cursor when the curson in Tab Bar? I try

          ui->tab->setCursor(Qt::PointingHandCursor);
          

          but the cursor change in the whole of tabwidget

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #3

          @mimamrafi
          install an eventfilter on the tabbar and on mousemove events check QTabBar::tabAt() >= 0 to set your cursor, else restore the cursor

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          M 1 Reply Last reply
          2
          • artwawA artwaw

            @mimamrafi I don't think you can without subclassing; there is no header property that would return the tab headers only.

            M Offline
            M Offline
            mimamrafi
            wrote on last edited by
            #4

            @artwaw I think it could. I using 'if' method. when the cursor enters the widget area, it changes. But i know this is newbie's method so it just for static window (I still can't how to make dynamically when we resize the window)

            1 Reply Last reply
            0
            • raven-worxR raven-worx

              @mimamrafi
              install an eventfilter on the tabbar and on mousemove events check QTabBar::tabAt() >= 0 to set your cursor, else restore the cursor

              M Offline
              M Offline
              mimamrafi
              wrote on last edited by
              #5

              @raven-worx yes, I'm using mouse movement event filter. But I still can't get the tab bar

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mimamrafi
                wrote on last edited by
                #6

                Hey, I solved this problem. This is my last code

                //maingui.h
                #include <QTabBar>
                ...
                private slots:
                ...
                    void mouseMoveEvent(QMouseEvent *event);
                
                private:
                    QList<QTabBar *> tabBar ;
                

                This is the CPP File

                //maingui.cpp
                MainGUI::MainGUI(QWidget *parent)
                    : QDialog(parent, Qt::WindowTitleHint |  Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint),
                    ui(new Ui::MainGUI)
                {
                    ui->setupUi(this);
                    setMouseTracking(true);
                ...
                }
                
                void MainGUI::mouseMoveEvent(QMouseEvent *event){
                    tabBar = this->ui->tabWidget->findChildren<QTabBar *>();
                    tabBar.at(0)->setCursor(Qt::PointingHandCursor);
                }
                

                But sometimes its not initialize for the first time. Thank you

                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