Results 1 to 4 of 4

Thread: QTabWidget and .setTabsClosable(True)

  1. #1
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTabWidget and .setTabsClosable(True)

    I do not quite understand why setting the TabsClosable as true does not automatically instantiate the close button closes the tabs.

    I am a newbie, that is why I am here. I have looked over the QEvents class and even tried connecting my QTabWidget's tabCloseRequested signal, but I must be doing something incorrect.

    How can I get my tabs to close when the buttons is pressed?

  2. #2
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget and .setTabsClosable(True)

    You can close close the tab by connecting the tabCloseRequested ( int index ) signal to a slot like
    connect(tabWidget, SIGNAL(tabCloseRequested ( int )), this, slot(closeTab(int))).
    The whole point I think is to validate the closing of the tab.
    eg the following slot will close the clicked tab except if it is the first tab
    void closeTab(int index)
    {
    if (!index)
    tabWidget->removeTab(index);
    }

  3. #3
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget and .setTabsClosable(True)

    Quote Originally Posted by Rhayader View Post
    You can close close the tab by connecting the tabCloseRequested ( int index ) signal to a slot like
    connect(tabWidget, SIGNAL(tabCloseRequested ( int )), this, slot(closeTab(int))).
    I am not sure if you read that I had been trying to do that. I am using PyQt also, so there is going to be a difference in syntax.

    When I try
    Qt Code:
    1. self.connect(self.chatView, QtCore.SIGNAL('QtGui.QTabWidget.tabCloseRequested(int)'), self, QtCore.SLOT('closeTab(int)'))
    To copy to clipboard, switch view to plain text mode 

    I am told that the slot does not exist.

    When I try
    Qt Code:
    1. self.connect(self.chatView, QtCore.SIGNAL('QtGui.QTabWidget.tabCloseRequested(int)'), self, QtCore.SLOT(self.closeTab))
    To copy to clipboard, switch view to plain text mode 
    I am told that the slot argument is an instance method. And if I place the parenthesis behind it, (int), Python will try and call the instance right away.

    When I try
    Qt Code:
    1. self.connect(self, QtCore.SIGNAL('tabCloseRequested(index)'), self.closeTab)
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. self.connect(self.chatView, QtCore.SIGNAL('tabCloseRequested(index)'), self.closeTab)
    To copy to clipboard, switch view to plain text mode 

    nothing happens.

  4. #4
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget and .setTabsClosable(True)

    Finally saw a working example:
    Qt Code:
    1. QtCore.QObject.connect(self.chatView, QtCore.SIGNAL('tabCloseRequested(int)'), self.closeTab)
    To copy to clipboard, switch view to plain text mode 

    I was reading how I would need to go through QObject, but I wasn't sure how the computer need to be told that way. Thanks.

Similar Threads

  1. Can't see widget, yet isVisible() returns true
    By MattPhillips in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2010, 12:56
  2. setTabsClosable just for few tabs
    By wirasto in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2009, 09:13
  3. Qt for S60, compiler warning regarding TRUE/FALSE
    By Archimedes in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 22nd October 2009, 14:09
  4. why Qt's forever macro is for(;;) rather than while(true).
    By babu198649 in forum General Programming
    Replies: 1
    Last Post: 13th June 2009, 14:21
  5. Is this true, Qt lgpl license..
    By tgreaves in forum General Discussion
    Replies: 5
    Last Post: 8th March 2009, 11:34

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.