Qt creator - .ui form displaying in new window - c++

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.

Related

Open QDialog from Main Window in Qt Designer

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.

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

How to acces other ui files in Qt Creator

How can I acces other ui files from code using Qt Creator?
I am trying to create a small text editor. As always, I designed the main window by pressing on the Design button . After that , I created a new ui file from Qt creator called about.ui (the IDE also added about.h and about.cpp ). The main window's functions(like on_button_cliked() ) are in the file textedit.cpp
I created a small menu with an about entry, and then I went to Action Editor ,I selected the entry , Go to Slot, and the trigerred();
The IDE created all the things for me, so all I need is to define the function.
How can I acces the about ui that I created earlier?
Thanks in advance
You don't need the access to the '.ui' file. Qt's ui application does everything for you. All you need now is to create an object of your About class with MainWindow as a parent and show it.
The approximate code will be:
#include "about.h"
// ...
void MainWindow::on_about_triggered()
{
About dialog(this);
dialog.exec();
}

Dynamic QT4 Menu in C++

I am using C++ and QT4 on Linux. I wish to add items to the menubar at runtime. My main GUI containing the menubar was designed with QT Designer and setup in the first line of code below.
In my main window constructor I have the following test code and it compiles fine. However, the new submenu bar and its item do not appear when the program is executed. I'm guessing Qt needs to be told to update the menubar somehow. Any ideas?
// Setup the user interface
m_ui.setupUi(this);
QMenu * iObjectsMenu = new QMenu(tr("Objects"), m_ui.menubar); //m_ui.menubar.menu_View->addMenu(tr("Objectz"));
QAction * menu_testAction = new QAction(tr("Test"), m_ui.menubar);
iObjectsMenu->addAction(menu_testAction);
The way you're doing it, you need to put the menu somewhere and you haven't done so.
I do it a little differently. When you make menus in the designer they have pointers in the ui member. You can then manipulate that menu quite easily.
For example, I wanted a menu that contains all the toolbars and dock windows that can be shown/hidden. I looked at the code that makes QMainWindow::createPopup() and made my own external function construct_view_menu(QMainWindow * parent, QMenu * view_menu). It's called during the main window initialization with construct_view_menu(this, ui.menu_View). Function just appends more menus and actions to that menu. The menu_View is just an empty menu I created with the designer.
I found this the easiest way to go about it, but you can also create new menus and then append or insert them into the menubar; it's this latter step you've neglected.
I would just generate the menu in your setup code rather than the ui, keep a member variable that points to the QMenu (allocated with new)

Floating/Embedded QDockWidget in a QWidget (KXmlGuiWindow's CentralWidget designed in QT Designer)

I'm just trying to get into QT (and KDE) program, and have hit a snag trying to add a floatable, draggable QDockWidget to the .ui file (based as a QWidget) that is embedded into my KDE 4 program.
This is all from the basic template provided by KDevelop 4, so while I understand what's going on, I just don't know the best way to change it.
Here's the deal: main.cpp spawns a new AEmpire window, which starts the whole show off:
AEmpire::AEmpire()
: KXmlGuiWindow(),
m_view(new AEmpireView(this)),
m_printer(0)
{
// tell the KXmlGuiWindow that this is indeed the main widget
setCentralWidget(m_view);
setupActions();
setupGUI();
}
When a new AEmpireView(this) is created (which inherits from QWidget) and is assigned to m_view, this constructor is called:
AEmpireView::AEmpireView(QWidget *)
{
ui_aempireview_base.setupUi(this);
settingsChanged();
setAutoFillBackground(true);
}
So, when I am editing the ui to my program in QT Designer, I'm actually editing the AEmpireView_base ui file, which is a QWidget. It just represents the main view of the KXmlGuiWindow (derived from QMainWindow) and is loaded at runtime.
So, how do I add floatable, draggable QDockWidgets into my main application? Is designing them separately, and add them to the UI the best option? Or maybe removing the entire AEmpireView class, and making my ui file directly represent a KXmlGuiWindow object to be loaded by the AEmpireClass?
Or am I totally overlooking something obvious? Thanks for reading!
I would design the QDockWidget contents as separate UI files. Then create them and stick them into the QDockWidgets in the AEmpire constructor.