Results 1 to 7 of 7

Thread: tabsClosable not working...! how to close tabs?

  1. #1
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default tabsClosable not working...! how to close tabs?

    I have Qt creator 2.3.0(based on Qt 4.7.4)
    In my program i created a tab using designer...and adding tabs to it dynamically...(wrote code for that)
    That works fine...But i needed close button on the tabs....
    so add the
    Qt Code:
    1. ui->tabWidget->setTabsClosable(true);
    To copy to clipboard, switch view to plain text mode 

    but it displays close button, but when i click on that tab wont close!!!
    whats wrong here? please somebody help me

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: tabsClosable not working...! how to close tabs?

    Qt Code:
    1. QTabWidget *tabWidget = new QTabWidget( this );
    2. tabWidget->setTabsClosable( true );
    3. connect( tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(slotCloseTab()) );
    To copy to clipboard, switch view to plain text mode 
    Slot:
    Qt Code:
    1. void MainWindow::slotCloseTab()
    2. {
    3. QTreeWidget *m_pProps = dynamic_cast<QTreeWidget *>( tabWidget->currentWidget() );
    4.  
    5. disconnect( m_pProps, 0, 0, 0 );
    6.  
    7. m_pProps->close();
    8. m_pProps = NULL;
    9. }
    To copy to clipboard, switch view to plain text mode 

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

    aurora (12th December 2011)

  4. #3
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: tabsClosable not working...! how to close tabs?

    OMG....
    My main window contains tabwidget....
    In that i'm adding tabs dynamically.....when i tried the code given by u, it closed whole window, instead of that single tab!!!!!!!!!!!!!!
    please help me whats wrong, here?

  5. #4
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: tabsClosable not working...! how to close tabs?

    Write your example of a code of addition and tab closing

  6. #5
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: tabsClosable not working...! how to close tabs?

    I’m creating TabWidget using designer, before running the program and adding widget in runtime…in this case....i'm creating "tab one", "tab two", "tab three"....
    if i close “tab three”, then “tab three” closes thats fine,,,,
    But if i close “tab two”, then both “tab two” and “tab three” closes
    and if i close “tab one”, then all tab closes…i,e “tab one “, “tab two” and “tab three” closes….
    whats wrong here? please help me,,,,,

    MainWin.h
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public slots:
    6. void slotCloseTab(int index);
    7. }
    8. class MainWindow : public QMainWindow
    9. {
    10. Q_OBJECT
    11.  
    12. public slots:
    13. void slotCloseTab(int index);
    14. }
    To copy to clipboard, switch view to plain text mode 



    MainWin.cpp

    Qt Code:
    1. void MainWindow::DisplayFileContent(QString string)
    2. {
    3. textBox = new QTextBrowser;
    4. ui->tabWidget->addTab(textBox,string);
    5. connect(ui->tabWidget,SIGNAL(tabCloseRequested(int)),this,SLOT(slotCloseTab(int)));
    6. f.close();
    7. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void MainWindow::slotCloseTab(int index)
    2. {
    3. this->ui->tabWidget->removeTab(index);
    4. }
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: tabsClosable not working...! how to close tabs?

    This code looks fine (f.close() looks strange).
    From behavior description it looks like your slot is called more then once! When index value is bigger then number of pages this has no impact, that is why last pages are closed.
    Put break point there (void MainWindow::slotCloseTab(int index)) and check callstack for the is sources of this extra calls.


    edit: I know what is a problem. Every time you are creating new tab, you are making new connection between tabWidget and main window.
    Move connect from void MainWindow:isplayFileContent(QString string) to constructor of main window (after setupUi) and it will work as it should.
    Last edited by MarekR22; 12th December 2011 at 13:00.

  8. The following user says thank you to MarekR22 for this useful post:

    aurora (13th December 2011)

  9. #7
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: tabsClosable not working...! how to close tabs?

    Quote Originally Posted by MarekR22 View Post
    This code looks fine (f.close() looks strange).
    From behavior description it looks like your slot is called more then once! When index value is bigger then number of pages this has no impact, that is why last pages are closed.
    Put break point there (void MainWindow::slotCloseTab(int index)) and check callstack for the is sources of this extra calls.


    edit: I know what is a problem. Every time you are creating new tab, you are making new connection between tabWidget and main window.
    Move connect from void MainWindow:isplayFileContent(QString string) to constructor of main window (after setupUi) and it will work as it should.

    THANKS A LOT.. I moved connect to constructor...it worked fine...

Similar Threads

  1. midi child does not close when I call close()
    By qlands in forum Qt Programming
    Replies: 7
    Last Post: 29th July 2011, 22:25
  2. QT application not close after close the mainwindow
    By artome in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2011, 22:23
  3. Replies: 2
    Last Post: 6th May 2011, 08:02
  4. Replies: 2
    Last Post: 17th December 2010, 19:01
  5. main window close not working
    By hvranic in forum Newbie
    Replies: 2
    Last Post: 17th June 2010, 21:12

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.