Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to index Tab widget contents ?
Forum Update on Monday, May 27th 2025

How to index Tab widget contents ?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
4 Posts 2 Posters 523 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on 11 Oct 2023, 13:50 last edited by
    #1

    I have successfully build a common form to be used as needed.
    The form has "Tab" as main widget.
    Since each Tab is "indexed" , I can change desired Tab title using such index.

    Each and every Tab contains QEditText widget.

    How can I build a function to entry a text to the desired Tab and its QEditText?

    Is there a way to "index" the QEditText widget in each Tab?

    93007ea4-858d-4cc7-b126-95bb6859ebb7-image.png

    J 1 Reply Last reply 11 Oct 2023, 14:23
    0
    • A Anonymous_Banned275
      11 Oct 2023, 13:50

      I have successfully build a common form to be used as needed.
      The form has "Tab" as main widget.
      Since each Tab is "indexed" , I can change desired Tab title using such index.

      Each and every Tab contains QEditText widget.

      How can I build a function to entry a text to the desired Tab and its QEditText?

      Is there a way to "index" the QEditText widget in each Tab?

      93007ea4-858d-4cc7-b126-95bb6859ebb7-image.png

      J Offline
      J Offline
      JonB
      wrote on 11 Oct 2023, 14:23 last edited by JonB 10 Nov 2023, 14:28
      #2

      @AnneRanch
      Each tab has a "page" as its widget. QWidget *QTabWidget::widget(int index) const returns the page/widget for the given tab. If you say that every one of your tabs has a QTextEdit for its widget, then:

      QTextEdit *textEdit = qobject_cast<QTextEdit *>(theTabWidget->widget(tabNum));
      if (textEdit != nullptr)
          qDebug() << "Success";
      else
          qDebug() << "Tab number" << tabNum << "does not have a QTextEdit as its (top-level) widget";
      

      So you can then use QTextEdit *textEdit as the text edit on tab number tabNum.

      (If by chance your tab pages are actually QWidgets --- which might be how they get created in Designer --- which then contain a QTextEdit we would have to alter the code slightly, but the principle holds.)

      A 1 Reply Last reply 11 Oct 2023, 14:42
      1
      • J JonB
        11 Oct 2023, 14:23

        @AnneRanch
        Each tab has a "page" as its widget. QWidget *QTabWidget::widget(int index) const returns the page/widget for the given tab. If you say that every one of your tabs has a QTextEdit for its widget, then:

        QTextEdit *textEdit = qobject_cast<QTextEdit *>(theTabWidget->widget(tabNum));
        if (textEdit != nullptr)
            qDebug() << "Success";
        else
            qDebug() << "Tab number" << tabNum << "does not have a QTextEdit as its (top-level) widget";
        

        So you can then use QTextEdit *textEdit as the text edit on tab number tabNum.

        (If by chance your tab pages are actually QWidgets --- which might be how they get created in Designer --- which then contain a QTextEdit we would have to alter the code slightly, but the principle holds.)

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on 11 Oct 2023, 14:42 last edited by
        #3

        @JonB said in How to index Tab widget contents ?:

        QTextEdit *textEdit = qobject_cast<QTextEdit *>(theTabWidget->widget(tabNum));
        if (textEdit != nullptr)
        qDebug() << "Success";
        else
        qDebug() << "Tab number" << tabNum << "does not have a QTextEdit as its (top-level) widget";

        Thanks, but I am little stumped.
        Here is my function which basically access the tab, not the containing "page" .
        QString MainWindow_C_CODE_FORM::TabTitle(QString text , int index)
        {
        // change tab title using index TOK
        ui->tabWidget->setTabText(index,text);
        // access QTextEdit ??
        QTextEdit *textEdit = qobject_cast<QTextEdit *>(theTabWidget->widget(tabNum));
        if (textEdit != nullptr)
        qDebug() << "Success";
        else
        qDebug() << "Tab number" << tabNum << "does not have a QTextEdit as its (top-level) widget";

        return text;
        

        }

        Can I still modify your code to work in this function?
        It does not have to work in the function , I can as well write another one.

        But I still do not get the access to the "page" .

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Anonymous_Banned275
          wrote on 11 Oct 2023, 15:14 last edited by Anonymous_Banned275 10 Dec 2023, 14:51
          #4

          I did try similar approach and it is sort-off working.
          Does that makes sense ?

               MWCCF->centralWidget()->topLevelWidget()->setWindowTitle("TEST windopw TITLE");
               MWCCF->centralWidget()->topLevelWidget()->topLevelWidget()->setToolTip("TEST TAB TOOL TIP");
          

          I have not figured out how to actually select desired Tab, so far only " top xyz..." is working.

          This approach is little cryptic ,but it would bypass the need for extra sub-funtion...

          ADDENDUM
          I think the above "topLevel" is OK for ONE level, it doe not makes much sense for multiple level...

          I like to modify / change my original post.

          Is there a way to scan thru the widgets / tabs to find a tab of specific title?

          I am still not sure how to find the correct widget - tab for example - pointer.

          1 Reply Last reply
          0

          1/4

          11 Oct 2023, 13:50

          • Login

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