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

Changing cursor in QTabBar



  • 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



  • 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



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


  • Moderators

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



  • @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)



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



  • 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


Log in to reply