Qt Designer:如何向按钮添加自定义插槽和代码 [英] Qt Designer: how to add custom slot and code to a button

查看:62
本文介绍了Qt Designer:如何向按钮添加自定义插槽和代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Qt4 Designer,我希望当我单击是"按钮时,将执行一些代码.当我单击否"时,将执行其他一些代码.我该怎么做?

I use Qt4 Designer and I want that when I click on the "yes" button, some code will execute. And when I click on the "no", some other code will be execute. How can I do it?

推荐答案

  1. 点击Edit Signal/Slots工具.

为您的按钮创建一个连接.为此,在设计器中选择您的按钮,方法是用鼠标左键按下它.将鼠标移动到主窗口中的某个位置,以创建与主窗口的连接(就像一条带有接地连接的红线).

Create a connection for your button. For this, select your button in the designer by pressing on it with the left button of the mouse. Move the mouse to some place in the main window to create a connection with the main window (it is like a red line with a earth connection).

当您松开鼠标按钮时,会出现 Configure Connection 对话框.

When you release the mouse button, the Configure Connection dialog appears.

在此对话框中,选择左侧文本控件(发送方)中的信号,例如 pressed().

In this dialog select a signal in the left text control (the sender), for example, pressed().

然后按右侧文本控件(接收器)中的 edit.出现MainWindow 的信号/插槽 对话框.

Then press edit in the right text control (the receiver). A dialog for the Signals/Slots of MainWindow appears.

在插槽面板中添加一个新插槽(绿色十字).文本 slot1() 出现.双击它以编辑该行并写入您的函数名称 doit_when_yes_ispressed().接受.

In the slot panel add a new slot (green cross). The text slot1() appears. Double click on it to edit the line and write instead the name of your function doit_when_yes_ispressed(). Accept.

现在在 Configure Connection 对话框中,您将在右侧的文本控件中看到您的函数.选择并接受.

Now in the Configure Connection dialog you will see your function in the right text control. Select and Accept.

在设计器中,您现在可以在小部件中看到信号和您的功能.

In the designer now you can see the signal and your function in the widget.

这篇关于Qt Designer:如何向按钮添加自定义插槽和代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆