Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Moved] tabclosable not working! please help me
Forum Updated to NodeBB v4.3 + New Features

[Moved] tabclosable not working! please help me

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aurora
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aurora
        wrote on last edited by
        #3

        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);

        }
        @

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          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);
          }

          @

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aurora
            wrote on last edited by
            #5

            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);
            }

            @

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved