How to acces other ui files in Qt Creator - c++

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();
}

Related

Qt GUI in Visual Studio..New Added Widgets through Qt Designer inaccessible

I wrote an application in Visual Studio and I needed to create a GUI for it so I decided to use Qt and I'm having a small but weird problem.
Let's say I add a Push button to the GUI in the Qt Designer. When I build the Application the UI Compiler creates the corresponding header file "ui_myApp.h" which has the new Push button.
When I Try to access the new Button and connect Signals and Slots the I can't find the Button. I only see old Widgets that I added before the Last build. It actually should show me "pushButton_2" and "pushButton_3" but I have only access to the pushButton and other Widgets before the last build.(See Figure)
I Checked the headerfile "ui_myApp.h" and the new Widgets are actually there. The Header file is correctly included. When I run my Application the new Button and new Widgets are there too. Why can't I access them when Connecting Signals and Slots in "myApp.cpp"??
Thanks!
Update
This may or may not help anyone. But if anyone ever faces the problem here how I solved it:
Each time I add new Widgets to my GUI using QT Designer I save the changes in the Form. Then I clean the Solution and Rebuild. Then I close Visual Studio and start it again. The new Widgets are accessible after these action. Not sure why.. but it does the job.

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 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.

QT Creator - QStackedWidget pages proglem

I started new project in Qt Creator (Qt Widget Project > Qt Gui Application) and I can't make stacked widget work properly.
I don't know how to change pages in stacked widget which I added using ui. Program object structure looks like this:
MainWindow(QMainWindow)
> centralWidget(QCentralWidget)
> mainStackedWidget(QStackedWidget)
and mainStackedWidget has page1, page2, page3.
I tried few things but I failed.
Basically all my tries were to somehow use mainStackedWidget in main.cpp but I didn't manage to figure out how to use object, created in ui, in main.cpp.
Any ideas?
The function you want is QStackedWidget::setCurrentIndex() or QStackedWidget::setCurrentWidget().
If you did not use Qt Designer, just use:
mainStackedWidget->setCurrentIndex(index);
If you did use Qt Designer, you would probably use:
ui->mainStackedWidget->setCurrentIndex(index);

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.