[Interest] Prevent right click on specific QTabWidget tab from emitting currentChanged(int) signal

Etienne Sandré-Chardonnal etienne.sandre at m4x.org
Fri Apr 18 11:21:58 CEST 2014


I would suppose that currentChanged() is emitted from mousePressEvent in
QTabBar. So right clicking will still change the current tab even if it
will not create a new one, which is not what we want.

I would suggest to install an event filter on tabBar().

If this is a right mouse button event, and the click point is in the "+",
just return true : this will prevent the QTabBar from handling the event.
Otherwise, return false : the QTabBar will process the event normally


Etienne


2014-04-18 10:57 GMT+02:00 Syam Krishnan <syamcr at gmail.com>:

>  On 04/17/2014 08:57 PM, Murphy, Sean wrote:
>
>
> Since there’s no reason to show that contextual menu on the ‘+’ tab, I’d
> like to disable the right click functionality just on the last tab, which
> I’m trying to do in the mousePressEvent for loop, by only looping to
> bar->count() – 1.  But the problem I’m having is that right-clicking on the
> ‘+’ tab emits currentChanged(int) BEFORE mousePressEvent() is called, so a
> new tab is being created in slotTabBarClicked(), so before the user right
> clicks, count() is 2, current index is 0, and the ‘+’ is on index 1.  Once
> the user right clicks on the ‘+’ tab, by the time we get to
> mousePressEvent(), count() is 3, current index is 1, and the ‘+’ tab is at
> index 2. So the mapping doesn’t work and I end up displaying a contextual
> menu on the newly created “Tab 2”, even though the user right-clicked on
> the ‘+’ tab.
>
>
>
> The behavior I want is right-clicking on the ‘+’ should do nothing; it
> shouldn’t add a new tab, it shouldn’t show a contextual menu.
>
>
>
> What am I missing?  Or how should I be trying to do this?  If there was a
> separate signal for left vs. right clicks, it’d be easy.  But I don’t see a
> way to easily detect in slotTabBarClicked(int) that it was a right-click
> that caused currentChanged(int) to be emitted…
>
>
> How about avoiding currentChanged() and creating new tab in
> mousePressEvent() if its the left mouse button?
>
>
> Syam
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140418/222bd1f3/attachment.html>


More information about the Interest mailing list