[Qt-interest] Adding menu for tabwidget

Andre Somers andre at familiesomers.nl
Thu Aug 20 12:49:51 CEST 2009


Yuvaraj R wrote:
> if i use like that ,while changing the tab ,menu wil show..
>  
> Thanks
>  
> Yuvaraj R
That is exactly what you asked for:
 > whenever user clciking the first tab ,menu will be display.

If you want other behaviour, please be a bit more specific in your 
question. When *do* you want the menu to pop up, if not on clicking the 
tab as you said at first?

André
>
> On Thu, Aug 20, 2009 at 2:26 PM, Andre Somers <andre at familiesomers.nl 
> <mailto:andre at familiesomers.nl>> wrote:
>
>     Yuvaraj R wrote:
>     > Dear All
>     >
>     >
>     > I have near 10 tabs in my tab widget.. I don't like to display
>     the 10
>     > tabs in tabwidget..
>     >
>     > I want to provide menu for tabwidget..
>     >
>     > whenever user clciking the first tab ,menu will be display.
>     >
>     > Any ideas?
>     >
>     > how do we get the notification,suppose  first tab icon is pressed..
>     >
>     >
>     Not that hard, I guess. I did not try it myself, but I would go
>     about it
>     like this:
>
>     QTabWidget is internally using QTabBar.
>     Subclass your QTabWidget, and re-implement virtual bool
>     eventFilter(QObject*, QEvent*). Now,
>     install an eventfilter on the internal tabBar from your subclassed
>     QTabWidget's constructor by calling
>     tabBar()->installEventFilter(this).
>     Now, your eventFilter method will get all the events mend for the
>     tabBar.
>     In in the event filter, you listen for events mend from your
>     tabBar. You
>     will probably be interested in events of type
>     QEvent::MouseButtonPress.
>     If you find such an event, you can use QTabBar::tabAt() to find out on
>     which tab the user clicked. Return true from your eventFilter
>     implementation if you handled the event, and false if you don't (that
>     will be the majority of events!). If you forget this, your tabs
>     will not
>     do anything anymore.
>
>     To pop up a menu, simply populate a QMenu object and call it's popup
>     method. You can use the coordinates of the mouse press event to
>     position
>     your popup menu.
>
>     Something along those lines should work, I think.
>
>     André
>
>     _______________________________________________
>     Qt-interest mailing list
>     Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>     http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>




More information about the Qt-interest-old mailing list