QT designer implementation error - qt

Actually i activated the Qt creator from terminal ex: in Linux sudo Qt-creator.sh. so qt application opens.when i tried to design the UI by drag and dropping the buttons , widgets to form a type of UI.when i run the application , it just show the blank widget. the designed part done in UI is not implemented. so whatever changes done in UI designer, is not displaying when i run application. i don't no where is the issue. is it because of activating the qt from terminal.
the reason for activating qt creator from terminal because, i need to cross compile the binary code for Arm-Cortex controller. so i need to follow the steps for setting compiler for arm-cortex in qt application.however the cross compilation works. but if any changes done on qt designer, when i run the application , i cant able to see the changes in UI output window.

Let me start by providing some background.
The Qt library allows you to create graphical user interfaces (GUI) using two alternative methods:
QWidgets
Qt Quick
QWidgets uses a set of widgets written in C++ that you can either create and layout yourself using explicit C++ code, i.e. manually, or use Qt Designer to edit the interface of your applicaiton in a WYSWIG style, producing a .ui. file that you use in a certain way later on.
Qt Quick uses a declarative approach to creation of the user interfaces, with a special markup language similar to HMTL. We're not discussing it here as it's not the approach that you're using.
Now let's take a closer look at how Qt Designer works in conjunction with .ui. files, given that our application is written in C+.
Once you launch Qt Designer and edit a form, then save it, a .ui. file is produced. It's an XML file containing an hierarchical description of the UI you've created. However, to be able to use that form as the GUI of your application, additional steps are required. You need to "tell" the application to use this .ui. file. This is done as follows. A special executable, the UI compiler uic, is invoked (automatically via qmake or cmake) to process the .ui file, and generate C++ code in form of a header file. You then include the header file in the file that includes your application code, and use one of the three available methods to create the UI of your application using the generated code.
The simplest method is shown below.
class MyForm : public QWidget
{
Q_OBJECT
public:
MyForm(QWidget *parent = 0);
private:
Ui::MyForm ui;
};
The ui member object is an object of the class generated by uic - the UI compiler mentioned above. The class contains code for creating the user interface, organizing it into a layout, and managing it throughout the application lifetime.
Then, in the .cpp file, we have the constructor:
MyForm::MyForm(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
}
The important call here is ui.setupUi(this). This creates the UI elements, applies the layout, and sets the layout on the widget provided as the argument to this call. Remember, our class inherits from QWidget.
The other approaches include inheriting from the generated class and dynamically loading the .ui file, omitting the compilation by uic, using the QUiLoader class. Please consult http://doc.qt.io/qt-5/designer-using-a-ui-file.html for further reference.
As far as starting Qt Designer from terminal, it has no effect on the problem. Moreover, starting a GUI application as root is highly discouraged on Linux, as it poses a major security issue.

Related

Pass arguments to constructor of widget within QStackedWidget

I have a graphical application written in C++ using Qt for an embedded device, which uses a QStackedWidget holding a number of UI widgets. The UI is all designed in Qt Creator's designer tool. When the user navigates through the device's application the display to be shown at that menu option is selected from the QStackedWidget and this all works great.
I'm now wanting to pass in a pointer to some configuration which is read from file when the application starts, but I can't seem to find a way to pass this pointer as an argument into the constructor of a widget on the QStackedWidget. Can anyone help?
My current approach is to call a function I've written within the class of a widget on the QStackedWidget, which works but doesn't feel the best way to do it.
To my knowledge if you want to use custom constructors - with other kinds of arguments than just the QWidget * parent - you have to create the ui programmatically:
create your custom StackedWidget with a special constructor,
prepare the global interface using the designer,
then add the StackedWidget in the constructor of the class after the setupUi method.
The other way is to use an initialization method after the construction of the item, like you did.

QFileDialog in a non-QT app

I have an app that uses a 3rd party GUI framework, but I want to open files with using QFileDialog. I'm thinking of instantiating a subclass of QWidget that is invisible and serves the purpose of serving up the dialog.
Is there a better way to do this?
I don't see any need for an invisible widget, since the file dialog doesn't require a a parent widget in order to be shown up.
Since the dialog needs to have a Qt event loop running, you will need to either show the dialog modally using exec(), or using one of the static functions like getOpenFileName.
To use any of the widget classes, including the file dialog, you need to have an instance of QApplication, although that instance doesn't have to have its exec() method called.

Qt Designer dock widgets children acess

I made a form using the Qt Designer which has some dockwidgets, these dockwidgets have some children widgets. How I can access the dockwidget and these child widgets in my mainwindow.cpp?
I highly recommend reading the docs for these kinds of things, but to give you a little head start, QDockWidget inherits from QWidget, which inherits from QObject:
https://doc.qt.io/qt-4.8/qobject.html#children
widget->children() would simply tell you the children of this widget. This would be needed if you didn't already know the names of the objects to be accessed directly, or had no reference to them.
Update
When you create objects in Qt Designer, and you run the setupUi(this) that is generated for you, inside of your MainWindow, you will then have access to all of the widgets you had set up as members. You can access them directly as they were named in Qt Designer. Please check out one of the numerous tutorials on getting started with Qt. Here is one that shows you how to make use of your ui file, and access the members from it: http://sector.ynet.sk/qt4-tutorial/my-first-qt-gui-application.html
You can also get a list of all the dockWidgets from the mainwindow with
QList<QDockWidget *> dockWidgets = findChildren<QDockWidget *>();
A similar technique works for getting toolbars etc. so you don't have to manually store a list as you create them

How to use subclassed class in qt

I've subclassed qt's pushbutton and now I would like to use it in my project (instead of qpushbutton) - the problem I have is that even if I add #include "mybutton.h" in ui_class it gets overwritten and I don't know what else can I do it.
Is there a way to have this button within designer on a panel just like the ordinary qpushbutton is?
Never modify the ui_Class file yourself. Any change you make there will be overwritten when the .ui gets compiled. Instead use the promote to functionality within QtDesigner.
If some forms must be designed, but certain custom widgets are
unavailble to the designer, we can substitute similar widgets to
represent the missing widgets. For example, we might represent
instances of a custom push button class, MyPushButton, with instances
of QPushButton and promote these to MyPushButton so that uic generates
suitable code for this missing class.

Qt App Ui Multi-Language Support:Change Images Accordingly

I use UI Designer to set up the form layout. And I want to change the button background image to another one when language setting is changed in the system setting of the phone. How can I do this? I know how to support multi-language of the text , but I dont know how to support mult-language of the image. Thanks
When the language is changed, QCoreApplication::installTranslator() will be called. From the documentation:
Installing or removing a QTranslator,
or changing an installed QTranslator
generates a LanguageChange event for
the QCoreApplication instance. A
QApplication instance will propagate
the event to all toplevel windows,
where a reimplementation of
changeEvent can re-translate the user
interface by passing user-visible
strings via the tr() function to the
respective property setters.
User-interface classes generated by Qt
Designer provide a retranslateUi()
function that can be called.
So you should reimplement QWidget::changeEvent() in your toplevel window and change the image there if the type() of the event is LanguageChange.

Resources