简体   繁体   中英

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM