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. Removing one Tab in a QTabWidget
Forum Updated to NodeBB v4.3 + New Features

Removing one Tab in a QTabWidget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 6.8k 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.
  • I Offline
    I Offline
    irobot
    wrote on last edited by
    #1

    Hi everyone!
    I have created a QTabWidget and I set the tabsClosable to true and I have also connected it to a slot like this:
    @
    connect(onglets,SIGNAL(tabCloseRequested(int)),this,SLOT(onfermerOnglet(int)));
    @
    Next, I implemented the onfermerOnglet(int i) slot like this:
    @
    void MainWindow::onfermerOnglet(int index){
    onglets->removeTab(onglets->currentIndex());
    }
    @

    where onglets is a tabwidget.

    When I execute my code, create some widgets (maybe 5) and I remove one (maybe the index ->2) it also removes all tab index above (it removes index 2, index 3 and index 4) instead of just removing tab index 2. Can someone help me?

    1 Reply Last reply
    0
    • I Offline
      I Offline
      irobot
      wrote on last edited by
      #2

      Problem solved

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        i'm not sure if that will be already a solution to your problem, but is there any reason why not using the index supplied by the signal?
        @
        void MainWindow::onfermerOnglet(int index)
        {
        onglets->removeTab(index);
        }
        @

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          [quote author="irobot" date="1367146830"]Problem solved[/quote]

          Please share the solution so you it may help others...

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • B Offline
            B Offline
            ByteWight
            wrote on last edited by
            #5

            I might want to add that you also have to delete the content inside the tab. Deleting the tab itself will not delete the page. Alternatively, you can delete the page itself, which will in turn delete the tab.
            @void MainWindow::onfermerOnglet(int index)
            {
            onglets->widget(index)->deleteLater();
            }
            @

            1 Reply Last reply
            0
            • I Offline
              I Offline
              irobot
              wrote on last edited by
              #6

              Hi raven-worx
              I forgot what exactly the problem was (sorry) but I think I have to tell you a little about the code. I have a MainWindow which contains a QTabWidget named onglets. I created a class named Widget that I display as tabs in onglets and I have a slot that creates tabs named createTab() where we create a Widget and add it to the QTabWidget. The error I made is to put the slot onfermerOnglet() in the createTab() and I remark that when I close maybe the last tab, it launches a loop and the index (onfermerOnglet() slot parameter) decreases. I don't know if I am really clear because I am struggling with my English.

              Why not using the index?You are right and I already correct it. About tab's content, I didn't know that so thanks again.

              Best Regards,
              iRobot

              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