在matlab中怎样用pushbutton点击一下使它所代表的值在0和1之间切换

在matlab中怎样用pushbutton点击一下使它所代表的值在0和1之间切换,第1张

设置一个全局变量,记录点击,通过判断这个全局变量进行赋值。

_OpeningFcn中:

global a;

a=0;

pushbuttonCallback中:

global a;

if a==1

a=0;

value=1;

else

a=1;

value=0;

end

就这样,最简单的方式

for(int i = 0; i < inum; i++)

{

if(pButton[i]GetCheck())

{

被选中

}

cstring

pedit[i]->GetwindowText(str);

strText为获取的文本

}

1、建立起你的QPushButton与i,j的关系,不管什么方法,比如二维数组,Map容器,甚至利用QTableWidget(QPushButton作为QTableWidgetItem放入对应表格)。不过本人建议Map容器,效率会高点,且不会引入表格控件(你未必喜欢那种视觉效果)。

2、对于每个QPushButton对象,

connect(digitalbutton,SIGNAL(clicked()),this,SLOT(getmove())); //digitalbutton对QPushButton进行遍历。

3、getmove()的实现:

void getmove() {

QPushButton digitalbutton = (QPushButton ) sender();

//上文sender()函数参见:>

你可以在pushbutton1的callback里面设置pushbutton2的enable或者visible属性(on或off),这样可以利用pushbutton1控制pushbutton2的使用,如果想调用pushbutton1的结果,那就把结果变量设置成全局变量,比如设成f,那么pushbutton2的callback调用该结果的话,只需在开始时定义global f即可。

水平有限,欢迎建议和挑错

PyQt5中按钮是一个QpushButton,可以提供一个点击的按钮来触发摸一个事件

按钮可以显示或者文字。

创建按钮

我们在第一节的mainwindow上创建一个按钮,代码如下:

from PyQt5 import QtCore, QtGui, QtWidgets

from PyQt5QtGui import QIcon

class Ui_mainWindow(object):

def setupUi(self, mainWindow):

mainWindowsetObjectName("mainWindow")

mainWindowsetWindowModality(QtCoreQtWindowModal)

mainWindowresize(624, 511)

selfcentralWidget = QtWidgetsQWidget(mainWindow)

selfcentralWidgetsetObjectName("centralWidget")

selfpushButton = QtWidgetsQPushButton(selfcentralWidget)

selfpushButtonsetGeometry(QtCoreQRect(240, 240, 75, 23))

selfpushButtonsetObjectName("pushButton")

mainWindowsetCentralWidget(selfcentralWidget)

selfretranslateUi(mainWindow)

QtCoreQMetaObjectconnectSlotsByName(mainWindow)

def retranslateUi(self, mainWindow):

_translate = QtCoreQCoreApplicationtranslate

mainWindowsetWindowTitle('您好')

mainWindowsetWindowIcon(QIcon('logopng'))

if __name__ == "__main__":

import sys

app = QtWidgetsQApplication(sysargv)

mainWindow = QtWidgetsQMainWindow()

ui = Ui_mainWindow()

uisetupUi(mainWindow)

mainWindowshow()

sysexit(appexec_())

image

这里只是单单创建一个按钮,按钮点击并没有任何作用。

同样按钮也可以进行各种设置。

image

除了上图几种方法,再介绍另外几种方法。

(1)设置字体大小,加粗,字型

font = QtGuiQFont()

fontsetFamily('微软雅黑')

fontsetBold(True)

fontsetPointSize(13)

fontsetWeight(75)

selfpushButtonsetFont(font)

这个方法是通用的。几乎PyQt其他组件也能用。

image

(2)设置

icon = QtGuiQIcon()

iconaddPixmap(QtGuiQPixmap("logopng"), QtGuiQIconNormal, QtGuiQIconOff)

selfpushButtonsetIcon(icon)

selfpushButtonsetIconSize(QtCoreQSize(50, 80))

selfpushButtonsetAutoRepeatDelay(200)

image

无图代码

from PyQt5 import QtCore, QtGui, QtWidgets

from PyQt5QtGui import QIcon

class Ui_mainWindow(object):

def setupUi(self, mainWindow):

mainWindowsetObjectName("mainWindow")

mainWindowsetWindowModality(QtCoreQtWindowModal)

mainWindowresize(624, 511)

selfcentralWidget = QtWidgetsQWidget(mainWindow)

selfcentralWidgetsetObjectName("centralWidget")

selfpushButton = QtWidgetsQPushButton(selfcentralWidget)

selfpushButtonsetGeometry(QtCoreQRect(240, 240,200, 53))

selfpushButtonsetObjectName("pushButton")

selfpushButtonsetText("一颗数据小白菜")

# selfpushButtonsetFlat(True)

selfpushButtonsetStyleSheet("background-color: rgb(164, 185, 255);"

"border-color: rgb(170, 150, 163);"

"font: 75 12pt \"Arial Narrow\";"

"color: rgb(126, 255, 46);")

mainWindowsetCentralWidget(selfcentralWidget)

selfretranslateUi(mainWindow)

QtCoreQMetaObjectconnectSlotsByName(mainWindow)

def retranslateUi(self, mainWindow):

_translate = QtCoreQCoreApplicationtranslate

mainWindowsetWindowTitle('您好')

mainWindowsetWindowIcon(QIcon('logopng'))

if __name__ == "__main__":

import sys

app = QtWidgetsQApplication(sysargv)

mainWindow = QtWidgetsQMainWindow()

ui = Ui_mainWindow()

uisetupUi(mainWindow)

mainWindowshow()

sysexit(appexec_())

image

有图代码

from PyQt5 import QtCore, QtGui, QtWidgets

from PyQt5QtGui import QIcon

class Ui_mainWindow(object):

def setupUi(self, mainWindow):

mainWindowsetObjectName("mainWindow")

mainWindowsetWindowModality(QtCoreQtWindowModal)

mainWindowresize(624, 511)

selfcentralWidget = QtWidgetsQWidget(mainWindow)

selfcentralWidgetsetObjectName("centralWidget")

selfpushButton = QtWidgetsQPushButton(selfcentralWidget)

selfpushButtonsetGeometry(QtCoreQRect(240, 240,200, 53))

selfpushButtonsetObjectName("pushButton")

selfpushButtonsetText("一颗数据小白菜")

# selfpushButtonsetFlat(True)

selfpushButtonsetStyleSheet("background-color: rgb(164, 185, 255);"

"border-color: rgb(170, 150, 163);"

"font: 75 12pt \"Arial Narrow\";"

"color: rgb(126, 255, 46);")

icon = QtGuiQIcon()

iconaddPixmap(QtGuiQPixmap("logopng"), QtGuiQIconNormal, QtGuiQIconOff)

selfpushButtonsetIcon(icon)

selfpushButtonsetIconSize(QtCoreQSize(50, 80))

selfpushButtonsetAutoRepeatDelay(200)

mainWindowsetCentralWidget(selfcentralWidget)

selfretranslateUi(mainWindow)

QtCoreQMetaObjectconnectSlotsByName(mainWindow)

def retranslateUi(self, mainWindow):

_translate = QtCoreQCoreApplicationtranslate

mainWindowsetWindowTitle('您好')

mainWindowsetWindowIcon(QIcon('logopng'))

if __name__ == "__main__":

import sys

app = QtWidgetsQApplication(sysargv)

mainWindow = QtWidgetsQMainWindow()

ui = Ui_mainWindow()

uisetupUi(mainWindow)

mainWindowshow()

sysexit(appexec_())

image

绑定按钮事件

我们给按钮绑定触发时间,用:

pushbuttonclickedconnect()

(1)退出事件

我们给按钮绑定退出事件:

selfpushButtonclickedconnect(mainWindowclose)

image

groupBox里面还要加一个显示控件吧 比如加个label

uilabel->setText(QString("%1")arg(uigroupBox->text()size()));

以上就是关于在matlab中怎样用pushbutton点击一下使它所代表的值在0和1之间切换全部的内容,包括:在matlab中怎样用pushbutton点击一下使它所代表的值在0和1之间切换、MFC 动态创建多个控件的问题、如何实现在一个二维QPushButton中一个button得到clicked时等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/10168073.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-06
下一篇2023-05-06

发表评论

登录后才能评论

评论列表(0条)

    保存