Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Stack widget pages not properly shown.
Forum Updated to NodeBB v4.3 + New Features

Stack widget pages not properly shown.

Scheduled Pinned Locked Moved Solved Mobile and Embedded
3 Posts 3 Posters 838 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.
  • K Offline
    K Offline
    kishore_hemmady
    wrote on last edited by
    #1

    I have a stackwidget with 5 pages.I also have a comboBox with 5 options corresponding to each page.
    I tried this below code but it was not proper.Plz suggest
    void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)
    {
    if(arg1 == "Video")
    {
    ui->AudioPage->hide();
    ui->TickerPage->hide();
    ui->RssPage->hide();
    ui->ImagePage->hide();
    ui->VideoPage->show();
    }
    else if(arg1 == "Image")
    {
    ui->VideoPage->hide();
    ui->AudioPage->hide();
    ui->TickerPage->hide();
    ui->RssPage->hide();
    ui->ImagePage->show();
    }
    else if(arg1 == "RSS")
    {
    ui->VideoPage->hide();
    ui->AudioPage->hide();
    ui->TickerPage->hide();
    ui->RssPage->show();
    ui->ImagePage->hide();
    }
    else if(arg1 == "Ticker")
    {
    ui->VideoPage->hide();
    ui->AudioPage->hide();
    ui->TickerPage->show();
    ui->RssPage->hide();
    ui->ImagePage->hide();
    }
    else if(arg1 == "Audio")
    {
    ui->VideoPage->hide();
    ui->AudioPage->show();
    ui->TickerPage->hide();
    ui->RssPage->hide();
    ui->ImagePage->hide();
    }
    }

    J.HilkJ 1 Reply Last reply
    0
    • K kishore_hemmady

      I have a stackwidget with 5 pages.I also have a comboBox with 5 options corresponding to each page.
      I tried this below code but it was not proper.Plz suggest
      void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)
      {
      if(arg1 == "Video")
      {
      ui->AudioPage->hide();
      ui->TickerPage->hide();
      ui->RssPage->hide();
      ui->ImagePage->hide();
      ui->VideoPage->show();
      }
      else if(arg1 == "Image")
      {
      ui->VideoPage->hide();
      ui->AudioPage->hide();
      ui->TickerPage->hide();
      ui->RssPage->hide();
      ui->ImagePage->show();
      }
      else if(arg1 == "RSS")
      {
      ui->VideoPage->hide();
      ui->AudioPage->hide();
      ui->TickerPage->hide();
      ui->RssPage->show();
      ui->ImagePage->hide();
      }
      else if(arg1 == "Ticker")
      {
      ui->VideoPage->hide();
      ui->AudioPage->hide();
      ui->TickerPage->show();
      ui->RssPage->hide();
      ui->ImagePage->hide();
      }
      else if(arg1 == "Audio")
      {
      ui->VideoPage->hide();
      ui->AudioPage->show();
      ui->TickerPage->hide();
      ui->RssPage->hide();
      ui->ImagePage->hide();
      }
      }

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @kishore_hemmady
      usually you controle the stackedwidget and the stackedwidget controlles the pages

      assuming your stackedwidget has the ObjectName stackedWidget you can write the following:

      void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)
      {
      if(arg1 == "Video")
      {
          ui->stackedWidget->setCurrentWidget(ui->VideoPage);
      }
      ...
      ...
      
      if(arg1 == "Audio")
      {
         ui->stackedWidget->setCurrentWidget(ui->AudioPage);
      
      }
      }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

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

        Hi,

        An even simpler solution would be to match the combo box index with the QStackedWidget content. Then you can connect them directly.

        connect(ui->comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), ui->stackedWidget, &QStackedWidget::setCurrentIndex);
        

        Way less code and it scales automatically when adding new widgets.

        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