Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QToolButton with QMenu stops working after switching tabs (QWebEngineView involved)
Forum Updated to NodeBB v4.3 + New Features

QToolButton with QMenu stops working after switching tabs (QWebEngineView involved)

Scheduled Pinned Locked Moved Unsolved QtWebEngine
13 Posts 3 Posters 1.6k Views 3 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.
  • S Offline
    S Offline
    soumyaniljana
    wrote on last edited by
    #3

    Hi, thanks for the response,
    I tested it by explicitly deleting QWebEngineView when switching tabs. The qDebug() output confirms the deletion is happening, but issue still persists. Any ideas on what might be causing this?

    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #4

      Can you boil this down to a small, compilable reproducer, which can be posted here?
      A web view is a complex beast. I've used it myself in a widgets application, in a dialog as a toplevel window of its own. At least there, it doesn't cause any trouble. I'll gladly have a look. Maybe it's even a bug, who knows.

      Software Engineer
      The Qt Company, Oslo

      S 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        Can you boil this down to a small, compilable reproducer, which can be posted here?
        A web view is a complex beast. I've used it myself in a widgets application, in a dialog as a toplevel window of its own. At least there, it doesn't cause any trouble. I'll gladly have a look. Maybe it's even a bug, who knows.

        S Offline
        S Offline
        soumyaniljana
        wrote on last edited by
        #5

        Hi, @Axel-Spoerl
        Thanks for your willingness to take a look!

        Unfortunately, I’m currently unable to post the code or zip file directly here as I don't currently have the privileges to upload a .zip file directly and it’s being flagged as spam due to its length or format. To work around that, I’ve uploaded the minimal, compilable reproducer as a GitHub Gist instead:
        https://gist.github.com/sjana0/9a022d41d3b050236779fdfba2a10088
        The project is self-contained and demonstrates the issue where the QToolButton menu stops opening after switching tabs with a QWebEngineView.

        Please let me know if you run into any issues running it or need a different format. I appreciate your help!

        1 Reply Last reply
        0
        • Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #6

          Hi @soumyaniljana,

          please post the code here explicitly, using the </> code tags. No zip files, no links.
          The community should see the code and not be referred to an external page, that might change over time.
          Cheers
          Axel

          Software Engineer
          The Qt Company, Oslo

          S 1 Reply Last reply
          1
          • Axel SpoerlA Axel Spoerl

            Hi @soumyaniljana,

            please post the code here explicitly, using the </> code tags. No zip files, no links.
            The community should see the code and not be referred to an external page, that might change over time.
            Cheers
            Axel

            S Offline
            S Offline
            soumyaniljana
            wrote on last edited by
            #7

            Hi @Axel-Spoerl ,

            Thanks again for your patience and help.

            I've been trying to post the minimal reproducible example using the </> code formatting as requested, but unfortunately, my post keeps getting flagged by Akismet as spam — even though I'm not including any links or external files. It seems the amount of code or structure might be triggering it.

            Would it be alright if I posted the code across a few smaller replies in the thread instead? Or if there’s another approach you’d recommend, I’d be happy to follow that.

            Really appreciate your time and support.

            Kind regards,
            soumyanil

            S 1 Reply Last reply
            0
            • S soumyaniljana

              Hi @Axel-Spoerl ,

              Thanks again for your patience and help.

              I've been trying to post the minimal reproducible example using the </> code formatting as requested, but unfortunately, my post keeps getting flagged by Akismet as spam — even though I'm not including any links or external files. It seems the amount of code or structure might be triggering it.

              Would it be alright if I posted the code across a few smaller replies in the thread instead? Or if there’s another approach you’d recommend, I’d be happy to follow that.

              Really appreciate your time and support.

              Kind regards,
              soumyanil

              S Offline
              S Offline
              soumyaniljana
              wrote on last edited by
              #8
              This post is deleted!
              1 Reply Last reply
              0
              • Axel SpoerlA Offline
                Axel SpoerlA Offline
                Axel Spoerl
                Moderators
                wrote on last edited by
                #9

                @soumyaniljana That looks incomplete.

                Software Engineer
                The Qt Company, Oslo

                S 1 Reply Last reply
                0
                • S Offline
                  S Offline
                  soumyaniljana
                  wrote on last edited by
                  #10
                  #include "mainwindow.h"
                  MainWindow::MainWindow(QWidget *parent)
                      : QMainWindow(parent),
                        webView(new QWebEngineView),
                        menuButton(new QToolButton),
                        tabs(new QTabWidget)
                  {
                      // Browser Tab
                      QWidget *browserTab = new QWidget;
                      QVBoxLayout *browserLayout = new QVBoxLayout(browserTab);
                      browserLayout->addWidget(webView);
                  
                  
                  	// if you dont initialize the webView, the QMenu dropdown works.
                  	// and same if you switch tab without initializing it and come back
                  	// vocabulary tab it again stops working.
                      webView->setUrl(QUrl("https://www.google.com"));
                  
                      
                  	// Vocabulary Tab
                      QWidget *vocabTab = new QWidget;
                      QVBoxLayout *vocabLayout = new QVBoxLayout(vocabTab);
                  
                      QMenu *menu = new QMenu;
                      menu->addAction("Edit");
                      menu->addAction("Delete");
                  
                      menuButton->setText("Menu");
                      menuButton->setMenu(menu);
                      menuButton->setPopupMode(QToolButton::InstantPopup);
                  
                      vocabLayout->addWidget(menuButton);
                  
                      // Add tabs to QTabWidget
                      tabs->addTab(vocabTab, "Vocabulary");
                      tabs->addTab(browserTab, "Browser");
                  
                      // Set central widget
                      setCentralWidget(tabs);
                  }
                  
                  1 Reply Last reply
                  0
                  • Axel SpoerlA Axel Spoerl

                    @soumyaniljana That looks incomplete.

                    S Offline
                    S Offline
                    soumyaniljana
                    wrote on last edited by
                    #11
                    #pragma once
                    
                    #include <QMainWindow>
                    
                    class QWebEngineView;
                    class QToolButton;
                    class QTabWidget;
                    
                    class MainWindow : public QMainWindow {
                        Q_OBJECT
                    public:
                        MainWindow(QWidget *parent = nullptr);
                    
                    private:
                        QWebEngineView *webView;
                        QToolButton *menuButton;
                        QTabWidget *tabs;
                    };
                    
                    S 1 Reply Last reply
                    0
                    • S soumyaniljana
                      #pragma once
                      
                      #include <QMainWindow>
                      
                      class QWebEngineView;
                      class QToolButton;
                      class QTabWidget;
                      
                      class MainWindow : public QMainWindow {
                          Q_OBJECT
                      public:
                          MainWindow(QWidget *parent = nullptr);
                      
                      private:
                          QWebEngineView *webView;
                          QToolButton *menuButton;
                          QTabWidget *tabs;
                      };
                      
                      S Offline
                      S Offline
                      soumyaniljana
                      wrote on last edited by
                      #12

                      Please include QTabWidget, QWebEngineView, QVBoxLayout, QToolButton, QMenu, QWidget
                      And that should now be the complete minimal example! Please let me know if it’s still missing anything or if there’s anything you'd like me to simplify further. I really appreciate your time and guidance.

                      Kind regards,
                      Soumyanil

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        soumyaniljana
                        wrote on last edited by
                        #13

                        Hi @Axel-Spoerl,
                        Just checking in to see if you had a chance to look at the code I posted earlier. I'd really appreciate any insights or suggestions when you get a moment.
                        Thanks again for your time and guidance.
                        Regards,
                        Soumyanil

                        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