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);
Related
I'm trying to create a Qt application with tabified QDockWidgets.
I know there is a QMainWindow::tabifyDockWidget to tabify QDockWidgets but since I'm doing everything related to UI in Qt Designer, I was wondering if there is some option in the designer to do so without adding extra code.
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.
Is there a good example or complete code for Qt Designer (creator) widget box like widget with QWidget or QFrame within? So it should work like QToolBox or QTabWidget but be expandable: possible to view few pages (widgets) at a time, not single one like QToolBox or QTabWidget or QStackedWidget provide.
Or need to write myself using QTreeWidget for example? Need same look and feel with same root decoration on category button (or panel) in in Qt Creator or with line like following:
+ ——- Category 1 ————
widgets
widgets
+ ——- Category 2 ————
widgets
widgets
etc
If it exists with plugin to Qt Creator - even better.
Created sample widget and plugin for Qt Designer, put it on GitHub if somebody else need this and want to improve: https://github.com/akontsevich/WidgetBox. It is ready for using however some points good to have improved:
Style category button (or panel) closer to Qt Creator (Designer) look
or like to LibreOffice Writer Properties Tool Box on the right side
Fix isPageExpanded propery change in Qt Designer
Hope for community participation or suggestions on these improvements.
Sample screenshots of current state:
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();
}
I am trying to make a dialog box like below in QT, the only problem is I have no idea what the widget is called. The bar on the left is like a tree-view widget, but when you click on it, it updates the text on the right. Does anybody happen to know what the widget is called or what widget(s) are required to perform this? I am using QT C++ on Windows.
There is an example with Qt showing you how to do this.
https://doc-snapshots.qt.io/4.8/dialogs-configdialog.html
If you're using Qt Creator as IDE, you can find it under the "Demos and Examples" tab in the Welcome Screen too.
It uses a QListWidget for the selector, and QStackedWidget to control the different pages. Connect the currentItemChanged signal of the list widget to change what page should be shown. Everything you'll need is in configdialog.cpp.
If you realy need to add QPushButton into QListWidget, use setItemWidget, or into ListView use QAbstractItemView::setIndexWidget