Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. How to select QTab ? (in C code )
Qt 6.11 is out! See what's new in the release blog

How to select QTab ? (in C code )

Scheduled Pinned Locked Moved Solved C++ Gurus
3 Posts 2 Posters 871 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    After much searching I realized that adding QFrame makes for easy duplicating but it is hard to iterate.

    Now I have this simple code iterating all QTab...

    But I cannot figure out How to activate / select specific QTab.

        // iterate - show all tab text
        for(int tabIndex = 0; tabIndex < ui->tabWidget_15->count(); tabIndex++)
        { 
            qDebug( ) <<"iterate @ index  " << QString::number(tabIndex);
            qDebug() <<"tab text @ index " << QString::number(tabIndex)<<
                      ui->tabWidget_15->tabText(tabIndex) ;
           // select as  current tab / QWidget 
           //  ui->tabWidget_15->widget(tabIndex)->?????
    ui->tabWidget_15->widget(tabIndex)->activateWindow(); // no go
    ui->tabWidget_15->widget(tabIndex)->focusWidget();    // no go
    ui->tabWidget_15->widget(tabIndex)->setFocus();       // no go
    ui->tabWidget_15->widget(tabIndex)->setEnabled(true); // no go 
    // TabWidget 
        }
    
    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      I assume that:

      • tabWidget_15 is a QTabWidget
      • with "activate / select" you mean setting the currentIndex of the tabWidget, i.e. determining which tab is being shown.

      If that is the case, look here.

      const int tabIndexToShow = 42; // or whatever you want
      ui->tabWidget_15->setCurrentIndex(tabIndexToShow);
      

      ...that should do what you want.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        Thanks for the idea.
        Looks convoluted , but works as expected.
        ui->tabWidget_15->setCurrentWidget(ui->tabWidget_15->widget(tabIndex));

        SOLVED

        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