PDA

View Full Version : Changing mouse cursor on QTabWidget only on the tabbar



si24803
3rd April 2012, 13:48
Hello all,
Yesterday I struggled to change the mouse cursor on hover over a tabbar on a QTabWidget.
If we use the setCursor() function on the QTabWidgetobject, the cursor will change regardless of which sub-widget the mouse is over. So for both the pane and the tab the cursor would be the same (in my case, a pointing hand).
I thought I could get the tabbar object from QTabWidget and set it's cursor but, unfortunately, as we all know, QTabWidget->tabbar() and setTabBar() are protected methods (and there might be good reasons for that).
After a few more bashing, I tried to go through the children of the QTabWidget, found the tabbar and set it's cursor. Here's how I did it:

QList<QTabBar *> tabBar = this->ui->tabWidget->findChildren<QTabBar *>();
tabBar.at(0)->setCursor(Qt::PointingHandCursor);

Hope it helps