PDA

View Full Version : QTabWidget - long pressure on tab



ilariari
13th April 2015, 14:31
Hallo,
working with QTabWidget, i have to intercept an event different from tabBarClicked(int) and tabBarDoubleClicked(int) (but they two as well): an event like "tabBarLengthenedPressure" as my customer wants to use this action to open a dialog and insert some data related to currentWidget.
How could I perform that?

Helps&hints appreciated, thank you very much!

^NyAw^
13th April 2015, 14:36
Hi,

Use a Timer. When you get a "mousePressEvent" you can start the timer. On "mouseReleaseEvent" you can stop it. If the timer fires you can open the dialog.

ilariari
13th April 2015, 15:24
Thank you ^NyAw^,
very good hint!
I'll create a new class derived from QTabBar and implementing my widget (instead of adding my widget directly to the QTabWidget).
I'll reimplement both: virtual void mouseMoveEvent ( QMouseEvent * event ) and virtual void mousePressEvent ( QMouseEvent * event ) and manage a QTimer "among" them.
It must work :) !

Lesiok
13th April 2015, 15:32
I think QElapsedTimer will better than QTimer.

ilariari
13th April 2015, 15:52
Great!
Thank you, Lesiok!

d_stranz
14th April 2015, 02:01
I'll create a new class derived from QTabBar

You really don't need to do that. You can simply install an event filter on your standard tab widget or tab bar and handle the events in that. Deriving from a QWidget just to handle one or two events is usually more work than the benefit you gain, and will probably lead to bugs. Easier to use the mechanism Qt provides for solving exactly this kind of problem.

ilariari
15th April 2015, 10:48
Ok, thank you!