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. Open dialog with menu item
Forum Updated to NodeBB v4.3 + New Features

Open dialog with menu item

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 3.1k 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.
  • B Offline
    B Offline
    BKBK
    wrote on last edited by BKBK
    #1

    Edit: Several working lines of code are shown in, what I think is, post 11. I have working code so declared this thread solved. Thank you.

    Novice alert. Please be tolerant of typos as I cannot copy paste to here.
    I have created a widget, and configured it thusly:

    QWidget *central_widget = new QWidget( this );
    setCentralWidget( central_widget )
    QGridLayout *sc_grid_layout = new QGridlayout( central_widget );  // code to fill in the grid not shown.
    QMenuBar *menu_bar = new  QMenuBar( central_widget );
    setMenuBar( menu_bar );
    QMenu *controls_option = new  QMenu( “Controls”, menu_bar );
    menu_bar->addMenu( controls_option )
    

    That much does work.
    When the user clicks the menu item “Controls” the intent is to display a dialog that has about 10 controls, line edits, radio buttons, etc. I don’t want a drop down menu. Do not stop at Go to collect $200. Just go directly to displaying the dialog. How can that be done?

    K 1 Reply Last reply
    0
    • B BKBK

      Edit: Several working lines of code are shown in, what I think is, post 11. I have working code so declared this thread solved. Thank you.

      Novice alert. Please be tolerant of typos as I cannot copy paste to here.
      I have created a widget, and configured it thusly:

      QWidget *central_widget = new QWidget( this );
      setCentralWidget( central_widget )
      QGridLayout *sc_grid_layout = new QGridlayout( central_widget );  // code to fill in the grid not shown.
      QMenuBar *menu_bar = new  QMenuBar( central_widget );
      setMenuBar( menu_bar );
      QMenu *controls_option = new  QMenu( “Controls”, menu_bar );
      menu_bar->addMenu( controls_option )
      

      That much does work.
      When the user clicks the menu item “Controls” the intent is to display a dialog that has about 10 controls, line edits, radio buttons, etc. I don’t want a drop down menu. Do not stop at Go to collect $200. Just go directly to displaying the dialog. How can that be done?

      K Offline
      K Offline
      kenchan
      wrote on last edited by
      #2

      @BKBK
      You need to add an action to your menubar see here for details

      B 1 Reply Last reply
      3
      • Maaz MominM Offline
        Maaz MominM Offline
        Maaz Momin
        wrote on last edited by
        #3

        @BKBK You can add a QToolBar instead of QMenuBar and then add QToolButtons to that toolbar.

        1 Reply Last reply
        1
        • B Offline
          B Offline
          BKBK
          wrote on last edited by
          #4

          I had not come across QToolBar so this is more involved that at first appears, as usual.
          In the QT4 Assistant for QMenuBar it states early on: … a list of pull-down menu items. QToolBar states: Toolbar buttons are added by adding actions, …
          So,…, I suspect both will work but need to try each and see what happens.
          Thank you for taking the time to post.

          JonBJ 1 Reply Last reply
          1
          • K kenchan

            @BKBK
            You need to add an action to your menubar see here for details

            B Offline
            B Offline
            BKBK
            wrote on last edited by
            #5

            @kenchan said in Open dialog with menu item:

            @BKBK
            You need to add an action to your menubar see here for details

            Thanks for that link. I'm having a bit of difficulty in understanding how class Action fits in but am working that link to understand it. Thanks for the reply.

            1 Reply Last reply
            1
            • B BKBK

              I had not come across QToolBar so this is more involved that at first appears, as usual.
              In the QT4 Assistant for QMenuBar it states early on: … a list of pull-down menu items. QToolBar states: Toolbar buttons are added by adding actions, …
              So,…, I suspect both will work but need to try each and see what happens.
              Thank you for taking the time to post.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @BKBK

              In the QT4 Assistant for QMenuBar it states

              Purely a heads-up: if you are a "novice", do you have legacy code to support which means you need to use Qt 4? Otherwise we are on Qt 5, and that's much shinier/newer/better....

              1 Reply Last reply
              0
              • B Offline
                B Offline
                BKBK
                wrote on last edited by BKBK
                #7

                JonB, Yes, we do have legacy code to support. Quite a lot and all but one QT Linux user has moved on so I am pretty much on my own. Most is QT3 but we do have QT 3 and Qt 4 installed and I am trying to force the issue to get to 4 then 5. Is this stuff obviously QT3 or 4? Yes, I can see many changes from 3 to 4, and presume many more for 5.

                I am not able to understand the use of QAction.
                The class: C_Strip_Chart has some labels and line edit widgets to show some of the parameters of a strip chart. It has been created with a menu bar that displays the text: "Controls" When the user clicks "Controls" another widget is to be displayed that provides the ability to change the parameters of the strip chart.
                The constructor for C_Strip_Chart instantiates
                C_Sc_User_Control * sc_user_control.

                It inherits QWidget and when the right code code is implemented can be displayed. Back to the constructor for C_Strip_Chart: it contains these lines:

                QMenu *menu_bar = new QMenuBar( central_widget );
                SetMenuBar( menu_bar )
                QMenu *strip_chart_menu = new QMenu( “Controls”, menu_bar )
                menu_bar->addMenu( strip_chart_menu );
                // That gets a menu bar displayed containing “Controls”  Now the part I don’t understand.
                QAction * open_user_control = new QAction( strip_chart_menu );
                Connect( open_user_control, SIGNAL( triggered() ),
                                  sc_user_control, SLOT( show() ) );
                

                I am tempted to write more about the intent, but suspect I am too far off the mark so simply ask:
                What must be different such that when the user clicks “Controls” the widget sc_user_controls is displayed?

                Please try to be tolerant of typos. I cannot copy paste from my work computer to my internet computer.

                JonBJ K 2 Replies Last reply
                0
                • B BKBK

                  JonB, Yes, we do have legacy code to support. Quite a lot and all but one QT Linux user has moved on so I am pretty much on my own. Most is QT3 but we do have QT 3 and Qt 4 installed and I am trying to force the issue to get to 4 then 5. Is this stuff obviously QT3 or 4? Yes, I can see many changes from 3 to 4, and presume many more for 5.

                  I am not able to understand the use of QAction.
                  The class: C_Strip_Chart has some labels and line edit widgets to show some of the parameters of a strip chart. It has been created with a menu bar that displays the text: "Controls" When the user clicks "Controls" another widget is to be displayed that provides the ability to change the parameters of the strip chart.
                  The constructor for C_Strip_Chart instantiates
                  C_Sc_User_Control * sc_user_control.

                  It inherits QWidget and when the right code code is implemented can be displayed. Back to the constructor for C_Strip_Chart: it contains these lines:

                  QMenu *menu_bar = new QMenuBar( central_widget );
                  SetMenuBar( menu_bar )
                  QMenu *strip_chart_menu = new QMenu( “Controls”, menu_bar )
                  menu_bar->addMenu( strip_chart_menu );
                  // That gets a menu bar displayed containing “Controls”  Now the part I don’t understand.
                  QAction * open_user_control = new QAction( strip_chart_menu );
                  Connect( open_user_control, SIGNAL( triggered() ),
                                    sc_user_control, SLOT( show() ) );
                  

                  I am tempted to write more about the intent, but suspect I am too far off the mark so simply ask:
                  What must be different such that when the user clicks “Controls” the widget sc_user_controls is displayed?

                  Please try to be tolerant of typos. I cannot copy paste from my work computer to my internet computer.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @BKBK
                  The above seems (to me) to do what would be expected. Clicking on Controls will call the show() slot of sc_user_control. One would imagine that should show whatever it is. If you know how to use a debugger/appropriate qDebug() statements you should verify that is getting called, and take it from there.

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @BKBK said in Open dialog with menu item:

                    C_Sc_User_Control * sc_user_control.

                    Just to be 100% sure, it does ?
                    C_Sc_User_Control * sc_user_control=new C_Sc_User_Control();

                    1 Reply Last reply
                    1
                    • B BKBK

                      JonB, Yes, we do have legacy code to support. Quite a lot and all but one QT Linux user has moved on so I am pretty much on my own. Most is QT3 but we do have QT 3 and Qt 4 installed and I am trying to force the issue to get to 4 then 5. Is this stuff obviously QT3 or 4? Yes, I can see many changes from 3 to 4, and presume many more for 5.

                      I am not able to understand the use of QAction.
                      The class: C_Strip_Chart has some labels and line edit widgets to show some of the parameters of a strip chart. It has been created with a menu bar that displays the text: "Controls" When the user clicks "Controls" another widget is to be displayed that provides the ability to change the parameters of the strip chart.
                      The constructor for C_Strip_Chart instantiates
                      C_Sc_User_Control * sc_user_control.

                      It inherits QWidget and when the right code code is implemented can be displayed. Back to the constructor for C_Strip_Chart: it contains these lines:

                      QMenu *menu_bar = new QMenuBar( central_widget );
                      SetMenuBar( menu_bar )
                      QMenu *strip_chart_menu = new QMenu( “Controls”, menu_bar )
                      menu_bar->addMenu( strip_chart_menu );
                      // That gets a menu bar displayed containing “Controls”  Now the part I don’t understand.
                      QAction * open_user_control = new QAction( strip_chart_menu );
                      Connect( open_user_control, SIGNAL( triggered() ),
                                        sc_user_control, SLOT( show() ) );
                      

                      I am tempted to write more about the intent, but suspect I am too far off the mark so simply ask:
                      What must be different such that when the user clicks “Controls” the widget sc_user_controls is displayed?

                      Please try to be tolerant of typos. I cannot copy paste from my work computer to my internet computer.

                      K Offline
                      K Offline
                      kenchan
                      wrote on last edited by kenchan
                      #10

                      @BKBK
                      I thought you are supposed to add the action to the menu at some point unless it is an action group, which I don't think it is, is it?

                      strip_chart_menu->addAction(open_user_control);
                      
                      1 Reply Last reply
                      1
                      • B Offline
                        B Offline
                        BKBK
                        wrote on last edited by BKBK
                        #11

                        First, my solution may not be the best so feel free to comment.
                        Here are some extracted code fragments that do the job.
                        This is the constructor for the widget that contains the strip chart and some explanatory values such at time and the limits of what is displayed.

                        C_Strip_chart::C_Strip_chart( QWidget *parent ) :QmainWindow( parent )
                        {
                        	// Create the widget the provides control of the strip chart.  It provides the ability to select
                        	// the parameter plotted, set the time span, etc.  The strip chart is a diagnostic tool.  There is 
                        	// the need to make it small while other things are observed.  Therefore the controls for the
                           	// strip chart are displayed independently of the plotted point.  Sc = Strip Chart.
                        sc_user_control = new C_SC_User_Control( );  // note: no parent.
                        sc_user_control->hide();
                        ….
                        QMenuBar  * menu_bar = new QMenuBar( central_widget );
                        SetMenuBar( menu_bar )
                        	// Line numbers are for easy reference below
                        1 QMenu *show_controls = menu_bar->( “Controls” );
                        2 Show_controls->addAction( “Show”, this, SLOT( show_the_controls() ));
                        3 Show_controls->addAction( “Hide”, this, SLOT( hide_the_controls() ));
                        4 Show_controls->addAction( “Show 4”, sc_user_control, SLOT( show() ));
                        5 Show_controls->addAction( “Hide 4”, sc_user_control, SLOT( hide() ));
                        
                        	// these were tested and found to work.  Discussed below
                        6 menu_bar->addAction( “Direct Show”, this, SLOT( show_the_controls() ));
                        7 menu_bar->addAction( “Direct Hide”, this, SLOT( hide_the_controls() ));
                        8 menu_bar->addAction( “Direct Show 2”, sc_user_control, SLOT( show() ));
                        9 menu_bar->addAction( “Direct Hide 2”, sc_user_control, SLOT( hide() ));
                        
                        

                        The original versions and variations compiled but when ran there was a startup message that the slot could not be found. The buttons did not show and hide the user control widget. I cannot get back to them to show my errors, but concluded that a slot in a different widget could not be called directly with an addAction() operation. We thought we had to create a local function to make that call in the other class / widget.

                        Hence, lines 2 and three. The function show_the_controls() is part of class C_Strip_chart and within them they call the show() of the user controls class.

                        I wanted a menu item that directly showed and hid the controls widget rather than opening a menu list to do that. So I wrote lines 6 and 7.

                        At that point I wrote line 8 and 9 to repeat my error and demonstrate that the local function had to be called. However, I was a bit surprised when they worked. That means that I had errors in my original calls that I cannot duplicate right now, and that my earlier conclusion was wrong. (That a direct call to another widget’s function could not be done.) Then I added lines 4 and 5 which work.

                        So, now this shows several ways of implementing the menu control so desired. Lines 4 and 5 follow what I suspect is the commonly used format, build a drop down menu and those items perform the operations desired. Lines 8 and 9 demonstrate that a menu item can directly initiate an action rather than just showing a menu list.

                        This has consumed a couple of days of my time.
                        I send my thanks to each that took the time to read and post.

                        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