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. Render a widget on top of others at runtime

Render a widget on top of others at runtime

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 568 Views 2 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.
  • franco.amatoF Offline
    franco.amatoF Offline
    franco.amato
    wrote on last edited by
    #1

    I have a mainwindow derived class having a QStackedWidget in the central part. Now when some event occur I need to show a custom widget at runtime on top of the central part. I tried using raise but it's not working

    // When I press a Game button i need to show the custom widget on top
    void BeastBurst::onGameButtonClicked(GameButton *button)
    {
        if (button == nullptr)
        {
            if (BeastBurst::m_activeGame)
            {
                BeastBurst::m_activeGame->hide();
                BeastBurst::m_activeGame = nullptr;
            }
            m_gamesToolBar->setSelectedButton(nullptr);
            return;
        }
    
        if (BeastBurst::m_activeGame && button == m_gamesToolBar->getSelectedButton())
        {
            BeastBurst::m_activeGame->hide();
            BeastBurst::m_activeGame = nullptr;
            m_gamesToolBar->setSelectedButton(nullptr);
            return;
        }
    
        if (BeastBurst::m_activeGame)
        {
            BeastBurst::m_activeGame->hide();
            BeastBurst::m_activeGame = nullptr;
        }
    
        std::shared_ptr<Game> selectedGame;
        for (auto game : m_games)
        {
            if (game->getGameId() == button->getGameId())
            {
                game->refresh();
                selectedGame = game;
                break;
            }
        }
    
        if (selectedGame)
        {
    // m_gameWindow is the custom widget I need to show on top of m_ui->mainContainer
            m_gameWindow->showGame(selectedGame->getGameId());
            m_gameWindow->showContent(0);
    
            QPoint pos = m_ui->mainContainer->mapTo(m_ui->centralWidget, QPoint(0, 0));
            m_gameWindow->move(pos);
            m_gameWindow->resize(m_ui->mainContainer->size());
    
            m_gameWindow->show();
            m_ui->mainContainer->lower(); // I tried to lower mainContainer
            m_gameWindow->raise(); // and raise gameWindow but it's not working
    
            BeastBurst::m_activeGame = selectedGame;
            m_gamesToolBar->setSelectedButton(button);
        }
    }
    

    Can I have a help

    Pl45m4P 1 Reply Last reply
    0
    • franco.amatoF franco.amato

      I have a mainwindow derived class having a QStackedWidget in the central part. Now when some event occur I need to show a custom widget at runtime on top of the central part. I tried using raise but it's not working

      // When I press a Game button i need to show the custom widget on top
      void BeastBurst::onGameButtonClicked(GameButton *button)
      {
          if (button == nullptr)
          {
              if (BeastBurst::m_activeGame)
              {
                  BeastBurst::m_activeGame->hide();
                  BeastBurst::m_activeGame = nullptr;
              }
              m_gamesToolBar->setSelectedButton(nullptr);
              return;
          }
      
          if (BeastBurst::m_activeGame && button == m_gamesToolBar->getSelectedButton())
          {
              BeastBurst::m_activeGame->hide();
              BeastBurst::m_activeGame = nullptr;
              m_gamesToolBar->setSelectedButton(nullptr);
              return;
          }
      
          if (BeastBurst::m_activeGame)
          {
              BeastBurst::m_activeGame->hide();
              BeastBurst::m_activeGame = nullptr;
          }
      
          std::shared_ptr<Game> selectedGame;
          for (auto game : m_games)
          {
              if (game->getGameId() == button->getGameId())
              {
                  game->refresh();
                  selectedGame = game;
                  break;
              }
          }
      
          if (selectedGame)
          {
      // m_gameWindow is the custom widget I need to show on top of m_ui->mainContainer
              m_gameWindow->showGame(selectedGame->getGameId());
              m_gameWindow->showContent(0);
      
              QPoint pos = m_ui->mainContainer->mapTo(m_ui->centralWidget, QPoint(0, 0));
              m_gameWindow->move(pos);
              m_gameWindow->resize(m_ui->mainContainer->size());
      
              m_gameWindow->show();
              m_ui->mainContainer->lower(); // I tried to lower mainContainer
              m_gameWindow->raise(); // and raise gameWindow but it's not working
      
              BeastBurst::m_activeGame = selectedGame;
              m_gamesToolBar->setSelectedButton(button);
          }
      }
      

      Can I have a help

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @franco-amato said in Render a widget on top of others at runtime:

      I have a mainwindow derived class having a QStackedWidget in the central part. Now when some event occur I need to show a custom widget at runtime on top of the central part. I tried using raise but it's not working

      What do you mean by "on top"? As separate window? What's the point of the stacked widget then?
      Why don't you just switch the stacked widget page to show your game widget?!

      @franco-amato said in Render a widget on top of others at runtime:

          m_gameWindow->show();
          m_ui->mainContainer->lower(); // I tried to lower mainContainer
          m_gameWindow->raise(); // and raise gameWindow but it's not working
      

      Of course it's not... because this is not what lower() and raise() are made for...

      The overall design seems to have some flaws which you should fix.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • franco.amatoF Offline
        franco.amatoF Offline
        franco.amato
        wrote on last edited by
        #3

        Hi,
        what I would like to achieve is to to create a semi translucent Game widget in order to "see" the widget that's behing it.
        Let's say that in my mainwindow I have a central widget that's a webview wich render some web sites. When I press a button I need to show a game widget in front of it and the website should be partially visible (due to the semi transparency of the Game widget)

        1 Reply Last reply
        0
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          @Pl45m4 said in Render a widget on top of others at runtime:

          What do you mean by "on top"? As separate window? What's the point of the stacked widget then?
          Why don't you just switch the stacked widget page to show your game widget?!

          From what I understand this is meant as a non-modal popup/overlay. Everything doesn't have to be in the same plane in a UI, overlap is sometime wanted.

          @franco-amato How is m_gameWindow created?
          If you want to show it on top of m_ui->mainContainer, just create it with mainContainer as the parent. Don't add it to a layout or the QStackedWidget. The mapTo shouldn't be necessary since its position would be relative to its parent. raise shouldn't be needed if its added the the container last.

          1 Reply Last reply
          3

          • Login

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