PDA

View Full Version : QTabWidget, QTabBar, double-click the tabText



jcr
21st September 2006, 17:57
Hello,

I am using a QTabWidget and, once a tab has been selected, I would like a click or double-click on its tabText or tabIcon to trigger a certain function. Ideally, the click to select that tab in the first place would not trigger the function. Any idea on how to proceed? Thanks.

jacek
21st September 2006, 18:01
You could try to install an event filter on QTabBar.

jpn
21st September 2006, 20:40
Take a look at:

void QTabBar::mousePressEvent (QMouseEvent *e)
int QTabBarPrivate::indexAtPos(const QPoint &p) const

in src/gui/widgets/qtabbar.cpp.

elcuco
21st September 2006, 21:44
This is something I used in my code, feel free to use and abuse. It does not handle double click, but it gives you a direction to your problem.



void qmdiTabBar::mousePressEvent ( QMouseEvent * event )
{
if (event->button() == Qt::MidButton)
{
int tabCount = count();
for( int i=0; i<tabCount; i++ )
{
if (tabRect(i).contains(event->pos()))
{
emit middleMousePressed(i, event->pos());
break;
}
}
}
else if (event->button() == Qt::RightButton)
{
int tabCount = count();
for( int i=0; i<tabCount; i++ )
{
if (tabRect(i).contains(event->pos()))
{
emit rightMousePressed(i, event->pos());
break;
}
}
}

QTabBar::mousePressEvent(event);
}