[Moved] tabclosable not working! please help me



  • 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
    @ui->tabWidget->setTabsClosable(true);@

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



  • Nothing is wrong here.
    [quote]When tabsClosable is set to true a close button will appear on the tab on either the left or right hand side depending upon the style. When the button is clicked the signal tabCloseRequested will be emitted.[/quote]
    You will have to connect to the tabCloseRequested signal and remove tabs using removeTab() as requested.



  • ok...i did it like this....
    but when i close one tab,, all tabs will closes....
    @connect(ui->tabWidget,SIGNAL(tabCloseRequested(int)),this,SLOT(slotCloseTab(int)));@

    @void MainWindow::slotCloseTab(int index)
    {
    this->ui->tabWidget->removeTab(index);

    }
    @



  • Please provide a small compilable example that allows me to reproduce your problem - I can't with the code you've posted.
    @
    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);

    public slots:
    void closeTab(int index);

    private:
    QTabWidget *tabWidget;
    };

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    {
    tabWidget = new QTabWidget;

    tabWidget->setTabsClosable(true);
    
    tabWidget->addTab(new QWidget, "Tab One");
    tabWidget->addTab(new QWidget, "Tab Two");
    tabWidget->addTab(new QWidget, "Tab Three");
    
    connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
    
    setCentralWidget(tabWidget);
    

    }

    void MainWindow::closeTab(int index)
    {
    tabWidget->removeTab(index);
    }

    @



  • I'm creating TabWidget using designer, before running the program and adding widget in runtime...in this case
    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
    @class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public slots:
    void slotCloseTab(int index);
    }
    @

    MainWin.cpp
    @
    void MainWindow::DisplayFileContent(QString string)
    {
    textBox = new QTextBrowser;
    ui->tabWidget->addTab(textBox,string);
    connect(ui->tabWidget,SIGNAL(tabCloseRequested(int)),this,SLOT(slotCloseTab(int)));
    f.close();
    }

    @

    @

    void MainWindow::slotCloseTab(int index)
    {
    this->ui->tabWidget->removeTab(index);
    }

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.