Changing cursor in QTabBar
-
wrote on 28 Dec 2021, 10:08 last edited by
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
-
wrote on 29 Dec 2021, 10:52 last edited by
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
-
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
wrote on 28 Dec 2021, 10:25 last edited by@mimamrafi I don't think you can without subclassing; there is no header property that would return the tab headers only.
-
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
@mimamrafi
install an eventfilter on the tabbar and on mousemove events check QTabBar::tabAt() >= 0 to set your cursor, else restore the cursor -
@mimamrafi I don't think you can without subclassing; there is no header property that would return the tab headers only.
wrote on 29 Dec 2021, 04:03 last edited by@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)
-
@mimamrafi
install an eventfilter on the tabbar and on mousemove events check QTabBar::tabAt() >= 0 to set your cursor, else restore the cursorwrote on 29 Dec 2021, 04:04 last edited by@raven-worx yes, I'm using mouse movement event filter. But I still can't get the tab bar
-
wrote on 29 Dec 2021, 10:52 last edited by
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/6