Using Qt/C++ template, how can I get a QML menubar on Windows?

2218
2
Jump to solution
08-16-2017 01:49 PM
NicholasLiccini
New Contributor II

Hi!

I am using the arcGIS Qt/C++ template that creates a QQuickView to show an application window, and I'd like to use a menubar item. My idea was to create an Application Window in QML and set the menubar from there, but the template sets you up with a QQuickItem which cannot have an Application Window as a parent.

What other ways are there to use Application Window with this template?

Is this possible or should I find a workaround?

Thanks!!

0 Kudos
1 Solution

Accepted Solutions
LukeSmallwood
Esri Contributor

Hi Nicholas - the template currently is not set up to provide you with an Application Window (please let me know if you think that is something important to include).

However, you can set your template up to use an ApplicationWindow with just a few changes:

in main.cpp you will need to: 

1. #include <QQmlApplicationEngine>

2. replace    QQuickView view; 
with
   QQmlApplicationEngine engine;

3. replace any occurrences of 
   view.engine()->
with
   engine.

4. remove any other references to 
   view

In your main.qml file, wrap the existing root item in an ApplicationWindow:

   ApplicationWindow {
       visible: true
       Test_application_window {
           width: 800
           height: 600
           // Create MapQuickView here, and create its Map etc. in C++ code
           MapView {
               anchors.fill: parent
               objectName: "mapView"
               // set focus to enable keyboard navigation
               focus: true
           }
       }

   }

Don't forget to set the visible property of the ApplicationWindow to true as this will be false by default. Once you have done that you should be able to use your QQuickItem created by the template as before and add a ToolBar etc. to the parent window.

I hope that helps you get going.

Luke

View solution in original post

2 Replies
LukeSmallwood
Esri Contributor

Hi Nicholas - the template currently is not set up to provide you with an Application Window (please let me know if you think that is something important to include).

However, you can set your template up to use an ApplicationWindow with just a few changes:

in main.cpp you will need to: 

1. #include <QQmlApplicationEngine>

2. replace    QQuickView view; 
with
   QQmlApplicationEngine engine;

3. replace any occurrences of 
   view.engine()->
with
   engine.

4. remove any other references to 
   view

In your main.qml file, wrap the existing root item in an ApplicationWindow:

   ApplicationWindow {
       visible: true
       Test_application_window {
           width: 800
           height: 600
           // Create MapQuickView here, and create its Map etc. in C++ code
           MapView {
               anchors.fill: parent
               objectName: "mapView"
               // set focus to enable keyboard navigation
               focus: true
           }
       }

   }

Don't forget to set the visible property of the ApplicationWindow to true as this will be false by default. Once you have done that you should be able to use your QQuickItem created by the template as before and add a ToolBar etc. to the parent window.

I hope that helps you get going.

Luke

NicholasLiccini
New Contributor II

Thank you Luke! 

This worked and I think it will get me going a lot more quickly now. 

Personally I do think it would be nice to include support for Application Windows with the template. They seem very helpful and it would allow for easier development of applications with multiple windows

0 Kudos