简体   繁体   English

如何在QT Designer中重新绘制小部件

[英]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. 我才刚刚开始学习有关QT的一些编程知识,并希望从QT Creator的设计器部分开始,然后再研究.cpp和.h文件。 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. 但是我阅读的所有内容都描述了如何更改代码,而不是在UI编辑器中进行更改。 Even the QT Designer manual gives no demonstration of how to create a simple calculator in Designer. 甚至QT Designer手册也没有演示如何在Designer中创建简单的计算器。 They only show the code ( http://doc.qt.io/qt-5/designer-using-a-ui-file.html ). 它们仅显示代码( 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. 我已经从本页底部的链接中加载了该项目: http : //doc.qt.io/qt-5/qtdesigner-calculatorform-example.html ,但我仍然对它的工作方式感到困惑通过查看UI编辑器进行算术运算。 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. 同样,在Output QLabel的属性中也看不到任何东西使它成为Input1和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. 我们只说如果输出大于10,则将方框设为蓝色。 I see the palette in the Properties box, but how do I make it conditional, staying within the Designer portion of the Creator application? 我在“属性”框中看到了该调色板,但是如何使其成为条件的,并停留在Creator应用程序的Designer部分中?

Thanks! 谢谢!

You're searching for a way to execute simple code/actions directly from within qt-designer, without using any code behind. 您正在寻找一种直接从qt-designer内部执行简单代码/操作而不使用任何后面代码的方法。

That's not possible , if you use qt-designer and .ui files. 如果您使用qt-designer和.ui文件, 那是不可能的
You can connect slots to signals directly from the designer, but you have to implement those slots in your *.cpp file. 您可以将插槽直接连接到设计人员的信号,但是必须在* .cpp文件中实现这些插槽。

If you want to mix the UI design with your application logic take a look at QML . 如果要将UI设计与应用程序逻辑混合使用,请看一下QML

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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