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. [Solved] QTabWidget: how to detect a tab has been added (or removed)
Qt 6.11 is out! See what's new in the release blog

[Solved] QTabWidget: how to detect a tab has been added (or removed)

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

    Hi,

    I sub-classed QTabWidget to hide the tab bar if there is only one tab (tabBar()->hide() and tabBar()->show() work well for that), but my problem is where to check tab count. According to the doc, there is no signal when a tab is added or removed, and when adding or removing a tab, the current selected tab may not change. Maybe by reimplementing an event (but which one)?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can re-implement the tabInsterted/tabRemoved functions

      http://qt-project.org/doc/qt-4.8/qtabwidget.html#tabInserted
      http://qt-project.org/doc/qt-4.8/qtabwidget.html#tabRemoved

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Hi,
        think that the best way to do this is to create a signal in the dialog where you add new tabs and then create a slot in your tabWidget class that will issue a redraw (first remember the selected tab).
        In the constructor of the dialog add a reference or a pointer to you tabWidget and connect the signal/slot.
        Think this is straight forward and not real special.
        Greetz

        Greetz, Jeroen

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tilsitt
          wrote on last edited by
          #4

          Thanks SGaist, that is the solution I wanted. I feel dumb for having missed it.

          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