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. QWidgetAction not visible
Qt 6.11 is out! See what's new in the release blog

QWidgetAction not visible

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 3.7k 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.
  • Chris KawaC Offline
    Chris KawaC Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on last edited by
    #2

    setDefaultWidget() works only for a single container showing the action, so are you adding widgetAction also somewhere else (like toolbar or other menu that is shown earlier)?
    To show a widget for each container that shows the action subclass QWidgetAction, implement virtual method createWidget() and return a new instance of that widget.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      joval
      wrote on last edited by
      #3

      I've already read about it and no - this is the only place where I put it.

      But talking about this - I also tried to subclass QWidgetAction and override createWidget() in the first place - the same story.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #4

        Hm, that's odd.

        This works for me:

        class MyWidgetAction : public QWidgetAction {
        public:
            MyWidgetAction(QObject* parent = 0) : QWidgetAction(parent) {}
            QWidget* createWidget(QWidget *parent) {
                QProgressBar* pb = new QProgressBar(parent);
                pb->setRange(0,0);
                return pb;
            }
        };
        
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
            QMenu* trayMenu = new QMenu(this);
            MyWidgetAction* widgetAction = new MyWidgetAction(this);
        
            ui->mainToolBar->addAction(widgetAction); //without this works too
            trayMenu->addAction(widgetAction);
        
            QSystemTrayIcon* trayIcon = new QSystemTrayIcon(this);
            trayIcon->setContextMenu(trayMenu);
            trayIcon->show();
        }
        

        Can you see any relevant differences with what you have?

        1 Reply Last reply
        1
        • J Offline
          J Offline
          joval
          wrote on last edited by
          #5

          Not a single difference.

          I ran your code and the progress bar doesn't show.

          I'm using Ubuntu 12.04 (gnome3, unity).

          1 Reply Last reply
          0
          • Joe von HabsburgJ Offline
            Joe von HabsburgJ Offline
            Joe von Habsburg
            wrote last edited by
            #6

            Hello, I have same problem.

                QWidgetAction * wa = new QWidgetAction(ui->menubar);
                QPushButton *btn = new QPushButton("abc");
            
                wa->setDefaultWidget(btn);
                ui->menubar->addAction(wa);
            

            Not visible on ui. What is the problem here ?

            SGaistS 1 Reply Last reply
            0
            • Joe von HabsburgJ Joe von Habsburg

              Hello, I have same problem.

                  QWidgetAction * wa = new QWidgetAction(ui->menubar);
                  QPushButton *btn = new QPushButton("abc");
              
                  wa->setDefaultWidget(btn);
                  ui->menubar->addAction(wa);
              

              Not visible on ui. What is the problem here ?

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote last edited by
              #7

              @Joe-von-Habsburg hi,

              Did you test the code of @Chris-Kawa ?
              Which version of Qt are you using ?
              On which OS ?
              If Linux which desktop environment ?
              Which window manager ?

              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
              0
              • Joe von HabsburgJ Offline
                Joe von HabsburgJ Offline
                Joe von Habsburg
                wrote last edited by Joe von Habsburg
                #8

                I did not see any thing, I want to use QMenuBar, not QToolBar

                    class MyWidgetAction : public QWidgetAction {
                    public:
                        MyWidgetAction(QObject* parent = 0) : QWidgetAction(parent) {}
                        QWidget* createWidget(QWidget *parent) {
                            QPushButton* pb = new QPushButton("abc");
                            return pb;
                        }
                    };
                
                    QMenu* trayMenu = new QMenu(this);
                    MyWidgetAction* widgetAction = new MyWidgetAction(this);
                    ui->menubar->addAction(widgetAction);
                    trayMenu->addAction(widgetAction);
                
                    QSystemTrayIcon* trayIcon = new QSystemTrayIcon(this);
                    trayIcon->setContextMenu(trayMenu);
                    trayIcon->show();
                

                Qt: 6.10.2
                Os: Ubuntu 24
                desktop environment : GNOME

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

                  Can you check under KDE ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  Joe von HabsburgJ 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Can you check under KDE ?

                    Joe von HabsburgJ Offline
                    Joe von HabsburgJ Offline
                    Joe von Habsburg
                    wrote last edited by
                    #10

                    @SGaist Why ? I use gnome. What is the different ?

                    SGaistS 1 Reply Last reply
                    0
                    • Joe von HabsburgJ Joe von Habsburg

                      @SGaist Why ? I use gnome. What is the different ?

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote last edited by
                      #11

                      @Joe-von-Habsburg they don't have the same design. Gnome is closer to macOS and handles menu bars differently from KDE. This could be one of the reason you don't get the result you are looking for.

                      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
                      0
                      • Joe von HabsburgJ Offline
                        Joe von HabsburgJ Offline
                        Joe von Habsburg
                        wrote last edited by
                        #12

                        thanks for your reply and explain

                        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