Results 1 to 4 of 4

Thread: QTabWidget, QTabBar, double-click the tabText

  1. #1
    Join Date
    Jan 2006
    Posts
    73
    Thanks
    16
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTabWidget, QTabBar, double-click the tabText

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget, QTabBar, double-click the tabText

    You could try to install an event filter on QTabBar.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTabWidget, QTabBar, double-click the tabText

    Take a look at:
    • void QTabBar::mousePressEvent (QMouseEvent *e)
    • int QTabBarPrivate::indexAtPos(const QPoint &p) const

    in src/gui/widgets/qtabbar.cpp.
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget, QTabBar, double-click the tabText

    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.

    Qt Code:
    1. void qmdiTabBar::mousePressEvent ( QMouseEvent * event )
    2. {
    3. if (event->button() == Qt::MidButton)
    4. {
    5. int tabCount = count();
    6. for( int i=0; i<tabCount; i++ )
    7. {
    8. if (tabRect(i).contains(event->pos()))
    9. {
    10. emit middleMousePressed(i, event->pos());
    11. break;
    12. }
    13. }
    14. }
    15. else if (event->button() == Qt::RightButton)
    16. {
    17. int tabCount = count();
    18. for( int i=0; i<tabCount; i++ )
    19. {
    20. if (tabRect(i).contains(event->pos()))
    21. {
    22. emit rightMousePressed(i, event->pos());
    23. break;
    24. }
    25. }
    26. }
    27.  
    28. QTabBar::mousePressEvent(event);
    29. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Push button double click
    By curtisw in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 16:40
  2. Customize QTabBar or QTabWidget
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 08:39
  3. Replies: 5
    Last Post: 12th January 2006, 15:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.