Open QDialog from Main Window in Qt Designer - c++

All I would like to do is to be able to open a new dialog from my MainWindow. I want to be able to design the dialog in Qt designer and then use the signals and slots editor to link a button press in my main window to the display of a new dialog. The dialog needs to have a couple of line edits and buttons in it and I want to avoid writing a new class in C++ every time i want a different dialog.
How can I link my main window to another dialog i created in qt designer?

You won't be able to connect the signal to startup the dialog within the designer, this will have to be in the code. But you won't need a new custom class everytime, you could easily use one class implementing different widgets.
You will have to write some c++/design some dialog everytime, since you do want to have another dialog (or at least another setup in the same dialog). You could setup the dialog to have a QStackedWidget and have an index in the constructor for having one dialog with multiple pages.

Related

MFC: Use a dialog's class for a second dialog

I have an dialog with several buttons and sliders on it and am adding another button that should close the dialog and open another that is essentially a mini version it.
I need access to the buttons in the first dialog in the second mini dialog (since they should have the same functionality).
Is there a way to use the class from the first dialog on the second so that I have access to those buttons? I've tried right clicking the dialog and adding a class, but it makes me make a new one instead of being able to use an existing one.
Thanks in advance!

Custom menu actions in Qt Designer

I'm currently trying to use Qt Designer to build a GUI and I would like to customize slots of my menu actions.
E-g: I'd like the user to press a menu action and it'd show a widget if it is hidden or hide it if it is already visible.
Basically, what I want to do is execute some code of mine and not the default actions such as show() or hide().
So I'm wondering if I should create a subclass of QMenuBar, add custom slots to it, then create a plugin to use it inside Qt Designer or if I should create a subclass for QMenu or QAction ? Or maybe it isn't the right way to do that ?
I'm working under Visual Studio and I'm only using Qt Designer, not Qt creator.
I'm new to GUI and Qt programming and I'm a bit lost here.
Thanks in advance :)
You have basically 2 options:
Implement the custom logic in the Mainwindow sublcass.
For this, you simply add the slots required for your handling in the class, and make them available in Qt Designer. You can do this:
either in the Signal/Slot editor and click "Modify" and then click on the + Symbol. By this you make new slots available in QtDesigner;
or when your slot is called on_(senderName)_(signalName), Qt autowiring will automatically connect the signals, and you don't have to do this in code or desinger.
Create a QMenuBar subclass and implement the custom logic there.
Your case tell Qt Designer to select your specific subclass as replacement for the default QMenuBar by right-clicking on it, and select "Promote to...". In the new dialog, you can specify your custom class that will be used as replacement in actual code, but in design time a QMenuBar is used. With this mehtod, you don't have to write a separate plugin to make your class available in Qt Designer.
Note that with the second option, your custom logic will only be called when the actions are triggered through the menu bar, not by shortcuts or tool buttons
Create a slot in your class:
onMenuActionTriggered()
Use the connect() to react on action's signal:
connect(ui.myAction, SIGNAL(triggered()), this, SLOT(onMenuActionTriggered()));
In your slot you can do whatever you want.
Another solution (not my favourite one, but possible) is to use the auto-connect functionality, which means, by declaring a slot 'on_myAction_triggered()' (where myAction is the name of your QAction) you don't need to use the connect() since it is automatically connected by Qt
The menu bar is automatically added to any new form derived from QMainWindow (the default when creating a gui application, but you can create new main windows using file->new file or project... and selecting Qt->Qt Designer Form Class ).
To add options to it you simply click in the area labeled "Type here" and write your option text. When you do so an action will appear in a list in the lower part of Qt Designer. Right click on that action and select "go to slot". It will pop up a dialog with "triggered()" already selected for you. Simply click "Ok" and Qt Creator will take care of all the details and transport you to the body of the slot function.

Qt how to create a settings/configuration window

I was trying to find an example of creating a settings/configuration windows. The settings window is launched by clicking "Options" action in the menu item. I wanted to figure out how to open up a 2nd window from the main window. As well how the new window return the settings information back to main window. Tried to play around with the QDialog or some inherited dialog classes, but those are for limited uses, not for general setting window. Is there any example/documentation about this?
Have you seen this property browser. Similar to property editor in Qt Designer. qtpropertybrowser Image

Qt creator - .ui form displaying in new window

I'm in the process of creating a GUI in Qt creator. Right now I have different .ui forms that correspond with different parts of my GUI. My login.ui window appears when you first run the program. When you click the loginButton, a new window displays with my MainMenuScreen.ui form. My problem is I don't want the MainMenuScreen to open in a new window...I want the application to only have one window and the contents change...any way I can do this by keeping separate .ui forms and without using StackedWidgets? My LoginScreen.ui and MainMenuScreen.ui both extend QWidget and in my Login.cpp I have an onclick event function which calls show() and creates the new window of my MainMenuScreen.
Thanks!
I think you can just call the setCentralWidget() method of your QMainWindow to reset the widget that is displayed in the Window.

wxDialog with the wxMenuBar

I have tons of existing code using wxWidgets. The main window is wxDialog. Now I have to add a wxMenuBar to that dialog. But, in order to do it, the window should be derived from wxFrame.
Is it possible to add a wxMenuBar to the wxDialog?
If not, is it possible to convert existing code in a way that main window is derived from wxFrame instead from wxDialog?
It's not possible to add a native menu bar to a wxDialog, however, it is possible to use a non-native menu bar control like wxFlatMenuBar (not included with wxWidgets), and add it to the top of the dialog as if it was just another control. Also note though that besides being a non-native menu bar, you also won't be able to use some wxWidgets API to manage it like wxUpdateUIEvents.
There's at least a couple things you will need to take into consideration when changing a wxDialog to a wxFrame.
First, if your dialog is a modal dialog, you will need to manually set the new frame as modal (using wxWindow::MakeModal()) rather than calling ShowModal().
Second, if you had any event handlers setup for the affirmative (OK/Apply button for example) or escape (Cancel or window close) events, you will likely need to rewrite them to handle changes in window behavior.