Results 1 to 4 of 4

Thread: QTabWidget: how to close a tab by a click

  1. #1
    Join Date
    Nov 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default QTabWidget: how to close a tab by a click

    Is there a way to close a tab by mouse?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTabWidget: how to close a tab by a click

    try this code
    Qt Code:
    1. MyTabWidget::MyTabWidget(QWidget *parent)
    2. : QTabWidget(parent)
    3. {
    4. tabBar()->installEventFilter(this);
    5. }
    6.  
    7. bool MyTabWidget::eventFilter(QObject *o, QEvent *e)
    8. {
    9. if (o == tabBar() && e->type() == QEvent::MouseButtonPress) {
    10. QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(e);
    11. removeTab(tabBar()->tabAt(mouseEvent->pos()));
    12. return true;
    13. }
    14. return QTabWidget::eventFilter(o, e);
    15. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    arturo182 (23rd April 2009)

  4. #3
    Join Date
    Nov 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTabWidget: how to close a tab by a click

    Qt Code:
    1. tabAt(mouseEvent->pos()));
    To copy to clipboard, switch view to plain text mode 

    Спасибо, товарищ!

    <tnank you, comrade>

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTabWidget: how to close a tab by a click

    пожалуйста
    you're welcome.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 14:12
  2. close() function confusion
    By iamjayanth in forum Qt Programming
    Replies: 3
    Last Post: 13th November 2008, 10:45
  3. Replies: 11
    Last Post: 15th July 2008, 13:11
  4. close window when click on a label
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 07:35
  5. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 04:32

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.