Results 1 to 3 of 3

Thread: Disable close button from QTabWidget

  1. #1
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Disable close button from QTabWidget

    How to I remove close button from individual tab ?

    Found that but it works only for QTabBar I need that for QTabWidget which seems to not have this option there.

    http://www.qtcentre.org/threads/1945...Widget-QTabBar

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable close button from QTabWidget

    QTabWidget::setTabsClosable()

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Disable close button from QTabWidget

    Subclass QTabWidget, use QTabBar::tabButton() to access the button from the tab you want to modify and call hide() on it. Alternatively you can hack into the tabbar from an existing tab widget, like so:
    Qt Code:
    1. class HackedTabWidget {
    2. friend class SomeClass;
    3. };
    4.  
    5. void SomeClass::someMethod() {
    6. // ...
    7.  
    8. QTabWidget *tw = ...
    9. HackedTabWidget *htw = (HackedTabWidget*)tw;
    10. QTabBar *tb = htw->tabBar();
    11. tb->tabButton(0, QTabBar::RightSide)->hide();
    12. }
    To copy to clipboard, switch view to plain text mode 

    If you don't feel comfortable with hacking into the tabbar, use inheritance instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:

    migel (20th September 2011)

Similar Threads

  1. disable close button in QMessageBox
    By mentalmushroom in forum Qt Programming
    Replies: 9
    Last Post: 4th June 2011, 21:08
  2. How to add close button to each tab widget Qtabwidget?
    By kishore7771 in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2010, 08:42
  3. Disable Close button (X) of a QDialog
    By BrainB0ne in forum Qt Programming
    Replies: 29
    Last Post: 8th December 2009, 17:01
  4. Disable close button on QTabWidget/QTabBar
    By minimoog in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2009, 05:25
  5. how to disable X button to close th window
    By raghvendramisra in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2009, 20:01

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
  •  
Qt is a trademark of The Qt Company.