Use condition in the Qt Creator designer - qt

I'm pretty new to Qt, and I can't find an answer to very basic question:
is it possible to use conditions when using the ui designer?
for example, that if a var x is set to true widget 1 will be displayed, otherwise widget b will be displayed in the same area?
I know how to do it in the code but wondered if it possible using the design tool...

In my experience there is not a way to do it using the designer in a QWidgets application, though I have to admit I never really tried to do that. In a Qt Quick QML application you can probably use a binding on the visible property to hide/show the desired item.

Related

How to repaint a widget in QT designer

I am just beginning to learn some programming with QT, and would like to start with the designer portion of QT Creator, before diving into the .cpp, and .h files. I would like to do simple tasks like change the color of a box based on a condition, or perform some arithmetic. But everything I read describes how to the change the code, not do it in the UI editor. Even the QT Designer manual gives no demonstration of how to create a simple calculator in Designer. They only show the code (http://doc.qt.io/qt-5/designer-using-a-ui-file.html). I've loaded the project from the links at the bottom of this page: http://doc.qt.io/qt-5/qtdesigner-calculatorform-example.html, but I'm still stumped as to how it does the arithmetic from looking at the UI editor. I don't see any signals/slots indication an addition on the numbers in the spin boxes. Nor, do I see anything in the properties of the Output QLabel that makes it the sum of Input1 and Input2.
And just to add another level to this simple example, how could I change the color of the output box if a condition is met? Let's just say if the output is larger than 10, make the box blue. I see the palette in the Properties box, but how do I make it conditional, staying within the Designer portion of the Creator application?
Thanks!
You're searching for a way to execute simple code/actions directly from within qt-designer, without using any code behind.
That's not possible, if you use qt-designer and .ui files.
You can connect slots to signals directly from the designer, but you have to implement those slots in your *.cpp file.
If you want to mix the UI design with your application logic take a look at QML.

error dialog box with Qt quick

i'm programming a Qt Quick application and I'm looking for a possibility to display the user errors. In Qt widgets there is QMessageBox but i can not find any equivalent to this in Qt Quick.
Sure i can create a MessageBox by myself but I can't imagine that there is no given possibility?
I found an ebook on the official site here and there is an Dialog described on page 67 but it doesn't work anymore and i can't find any further information about that. Is it dropped in the current version?
Thanks in advance
There is no Qt-Quick component for this yet. What I do in my application is using the Window QML component. I set the modality property to Qt.WindowModal to have it as a modal Window. You can then use the Button component to create OK/Cancel buttons.
Another thing I do is create these modals dynamically when something wrong occurs using Qt.createComponent() in QML.
Edit: Just discovered a new Dialog component that will be released in Qt5.2 that seems to match what you are looking for: MessageDialog

qt equivalent for docking control to it's container in winforms

I'm trying out qt creator lately and i hate reading hours of docs and tutorials just for doing simple tasks.
So, in winforms i can drag & drop a control from toolbox and set the dock property so it automatically maximizes itself to it's container's size.
What is the equivalent of this behaviour in qt?
I googled this and found it strange that nobody wondered the same before.
There are differences between the concepts of WinForms and Qt. You need to study the concept of layouts. Take a look at the relevant part of the documentation of Qt Designer: Using Layouts in Qt Designer
Before a form can be used, the objects on the form need to be placed
into layouts. This ensures that the objects will be displayed properly
when the form is previewed or used in an application. Placing objects
in a layout also ensures that they will be resized correctly when the
form is resized.
Qt uses layouts. Add QHBoxLayout or QVBoxLayout to the parent widget.

Is there any way to set the visibility of QLabel in Qt Designer

I'm trying to make a QLabel not visible by default in Qt Designer. I can hard code it but I was wondering if there was a way to set this using the designer.
m_uiForm.aLabel->setVisible(false);
As far as I know, this is not possible from QtDesigner.
The only way to access setVisible directly from QtDesigner is when modifying connects you can find it as a slot.
The simplest way is just to set the visibility to false just like you are doing already.

Qt Creator -- how do I set the model of a QTreeView inside the Designer?

I'm learning Qt independently, and this may seem like an easy question (because it is). I primarily come from a Swing background, so the concepts are very similar.
My question:
I am using Qt Designer to create a QTreeView item in the UI Designer. How do I do something as simple as setting the model of the TreeView?
Usually I would do something like:
QTreeView *tree = new QTreeView();
tree->setModel( &myModel);
I don't even know how to get a reference to the QTreeView object that the UI Designer created. Any direction will be appreciated!
Depending on your version of Qt, your main window will either include as a member or privately inherit a class with all of your designer widgets. So, within MainWindow, e.g. either my_widget->show(); or ui->my_widget->show(); to show the widget, respectively.
In your case, my_tree_view->setModel(my_model);

Resources