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]How to refresh TabText dynamically?

[SOLVED]How to refresh TabText dynamically?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.6k 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.
  • Z Offline
    Z Offline
    zhanguoxiaoyan
    wrote on last edited by
    #1

    I have a QTabWidget and want to refresh the tab names dynamically. E.g., TabWidget has Tab1, Tab2, Tab3, Tab4 at the beginning. Then I close Tab2, the three Tab names should become Tab1, Tab2, Tab3.

    Now, I try to do it like follows:
    @ setUpdatesEnabled(true);
    for (int i = index; i < displayTabWidget->count(); i++) {
    tabName = "Curves";
    tabName += QString::number(i);
    setTabText(i, tabName);
    }
    displayTabWidget->repaint();@

    I put it inside the function closeTab(int index) and after removeTab(index) is called

    But this does not work...The Tab texts do not change

    Thanks a lot!

    1 Reply Last reply
    0
    • F Offline
      F Offline
      franku
      wrote on last edited by
      #2

      Hi, I've created a small MainWindow for you for that your code is working. Especially have a look on how you are using the setTabText function, without an object. Possibly you have derived your class from QTabWidget and mix some things up?

      @MainWindow::MainWindow(QWidget parent) :
      QMainWindow(parent)
      {
      QTabWidget
      tabWidget = new QTabWidget(this);
      setCentralWidget(tabWidget);

      tabWidget->addTab(new QWidget, "Tab 1");
      tabWidget->addTab(new QWidget, "Tab 2");
      tabWidget->addTab(new QWidget, "Tab 3");

      for (int i = 0; i < tabWidget->count(); i++) {
      QString tabName = "Curves";
      tabName += QString::number(i);
      tabWidget->setTabText(i, tabName);
      }
      }
      @

      This, Jen, is the internet.

      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