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

Murphy, Sean smurphy at walbro.com
Fri Apr 18 19:23:38 CEST 2014


I'll give that a shot.  I like that solution just from a code organization standpoint, so that all this behavior is contained in mousePressEvent() and I'm just deciding what to do based on whether it was a left or right mouse button, instead of having some code in mousePressEvent() and some in a custom slot connected to currentChanged().

Sean

From: interest-bounces+smurphy=walbro.com at qt-project.org [mailto:interest-bounces+smurphy=walbro.com at qt-project.org] On Behalf Of Syam Krishnan
Sent: Friday, April 18, 2014 4:57 AM
To: interest at qt-project.org
Subject: Re: [Interest] Prevent right click on specific QTabWidget tab from emitting currentChanged(int) signal

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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140418/0fa352a2/attachment.html>


More information about the Interest mailing list