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: Add new Tab from a QWidget tab
Forum Updated to NodeBB v4.3 + New Features

QTabWidget: Add new Tab from a QWidget tab

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 617 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.
  • P Offline
    P Offline
    Philipp DE
    wrote on last edited by
    #1

    Hi,

    I my application, I have a QTabWidget with several tabs.

    On tab of that QTabWidget is inside an QWidegt and I add this like

    ui->tabWidget->insertTab(1, new FormMember(0, this), "New Member");
    

    Until here, everything works fine.

    Now I am inside that FormMember Class (QWidget) and I like to create a new tab for my QTabWidget from there.

    I have no Idea how I can access to that QTabWidget (which is not part of my FormMember class) object to add a new tab.

    What would be the right way. Do I need to give a pointer as further parameter to my FormMember class or is there any better way to receive this.

    When I was working with c++ Builder 20 years ago it was no problem to call other object from other windows.

    JonBJ 1 Reply Last reply
    0
    • P Philipp DE

      Hi,

      I my application, I have a QTabWidget with several tabs.

      On tab of that QTabWidget is inside an QWidegt and I add this like

      ui->tabWidget->insertTab(1, new FormMember(0, this), "New Member");
      

      Until here, everything works fine.

      Now I am inside that FormMember Class (QWidget) and I like to create a new tab for my QTabWidget from there.

      I have no Idea how I can access to that QTabWidget (which is not part of my FormMember class) object to add a new tab.

      What would be the right way. Do I need to give a pointer as further parameter to my FormMember class or is there any better way to receive this.

      When I was working with c++ Builder 20 years ago it was no problem to call other object from other windows.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Philipp-DE
      You should really do this from the ui->tabWidget level, or send it a signal asking it to create another tab.

      But if you do want to be able to access the tabWidget from your FormMember, as you say you could pass the tabWidget for FormMember to store (naughty), or you can use FormMember's parent() or parentWidget() (I think the latter) to walk up the hierarchy (you may have to go a couple of steps, not just one, can't recall) till you hit a qobject_cast<QTabWidget*>(parent) != nullptr, and that will be the parent QTabWidget.

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

        Hi,

        Use @JonB first suggestion. Implement a proper API for that. Toying with parent widgets is usually sign of a wrong design.

        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
        2

        • Login

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