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] Allowing widgets contained in a QTabWidget to see index

[SOLVED] Allowing widgets contained in a QTabWidget to see index

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.4k 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.
  • N Offline
    N Offline
    nicky j
    wrote on last edited by
    #1

    Hello,

    I was wondering if it is possible to allow a widget within a QTabWidget to see the index number of the tab its in. Here is a piece of code that shows what I am trying to do:

    @
    tabWidget->addTab(new browseTab(this, "http://www.google.com/", ###) ,tr("Browser"));
    @

    My idea is this:

    1. when a new tab is added, create a new instance of the class browseTab.
    2. declare the parent, url, and index number in the browseTab class constructor.

    I have had success passing the URL on to browseTab in this manner, but I'm not sure how to send the index number. The index number should replace the ### symbols obviously. How can I pass the new tab's index number to the widget (browseTab) contained therein?

    Any help would be appreciated!
    Thanks!

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

      Hi,

      Use insertTab so you set the index yourself. Take a look at the documentation to see how it works, specially if you pass an out of range index.

      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
      • N Offline
        N Offline
        nicky j
        wrote on last edited by
        #3

        Sgaist,

        My program allows new tabs to be added dynamically (web browser). The tabs are movable, so you can drag and drop them with impunity. Since my last post, I've come up with a new system:

        1. When a new tab is created, the associate page is given a unique, random ID#.
        2. This ID# is saved into a QList. This QList associates an ID# with an index #. ie "791" is located at position 2 in the QList. 791 is the ID, 2 is the index.

        Heres the problem. When you linearly add tabs one after another, the QList increments in a predictable way: assigning a new index to each new ID. If I move a tab around, the QList doesn't update to move the ID to the correct index. Is there a way to use insertTab along with the drag-drop tabs? I don't think my system is the most efficient.

        Thanks for your help!

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nicky j
          wrote on last edited by
          #4

          I have solved the problem!

          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