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. QTabWidget: How to know when last tab is removed ?
Forum Update on Monday, May 27th 2025

QTabWidget: How to know when last tab is removed ?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.2k Views
  • 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.
  • E Offline
    E Offline
    elpidiovaldez5
    wrote on last edited by
    #1

    I have a program in which the user dynamically adds and removes tabs from a QTabWidget. I need the program to take action when the last tab is removed. I did something similar with a QSplitter by installing an event filter on the splitter and then checking four splitter->count()==0 when a QEvent::childRemoved event was sent. Unfortunately the QTabWidget does not seem to receive any childRemoved events. Is there any way of detecting this situation ? Note that the tabs are removed automatically by Qt when their page is deleted.

    The code is shown below:

    @bool DynamicDataFrame::eventFilter(QObject obj, QEvent event) {
    if (obj==splitter) {
    QChildEvent
    childEvent = dynamic_cast<QChildEvent >(event);
    if (!placeHolderFrame && childEvent && childEvent->type()==QChildEvent::ChildRemoved) {
    if (splitter->count()==0) {
    this->deleteLater();
    return false;
    }
    }
    }
    if (obj==tabArea) {
    QChildEvent
    childEvent = dynamic_cast<QChildEvent >(event);
    if (!placeHolderFrame /
    && childEvent && childEvent->type()==QChildEvent::ChildRemoved
    /) {
    if (tabArea->count()==0) {
    this->deleteLater();
    return false;
    }
    }
    }
    return false;
    }@

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SergioDanielG
      wrote on last edited by
      #2

      Hi elidiovaldez5.
      Maybe you can try capture signal "QTabWidget::tabCloseRequested()":http://qt-project.org/doc/qt-5.0/qtwidgets/qtabwidget.html#tabCloseRequested and verify if "QTabWidget::count":http://qt-project.org/doc/qt-5.0/qtwidgets/qtabwidget.html#count-prop it's equal to zero.
      Hope it's util.

      Regards.

      www.ftatv.com.ar El foro argentino de la TV libre

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

        you can listen to the "currentChanged() signal":http://qt-project.org/doc/qt-4.8/qtabwidget.html#currentChanged .
        If -1 is emitted then there is no tab left.

        --- 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
        • E Offline
          E Offline
          elpidiovaldez5
          wrote on last edited by
          #4

          Thanks very much. I'll give both of them a try.

          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