QT 控件和ID绑定 QObjectUserData

#ifndef CDATABIND_H
#define CDATABIND_H


#include <QObjectUserData>


class CDatabind : public QObjectUserData
{
public:
    CDatabind();


    void SetUserData(int ROw, int col);


public:
    int m_nRow;
    int m_nCol;






};


#endif // CDATABIND_H


#include "cdatabind.h"


CDatabind::CDatabind()
{
    m_nRow = -1;
    m_nCol = -1;
}

void CDatabind::SetUserData(int row, int col)
{
    m_nRow = row;
    m_nCol = col;
}



使用

 QPushButton *open = new QPushButton("打开");
        CDatabind *bindopen = new CDatabind();
        bindopen->SetUserData(i, 4);
        open->setUserData(0, bindopen);
        ui->tableWidget->setCellWidget(i, 4, open);
        connect(open, SIGNAL(clicked()), this, SLOT(OnBtnOpendoor()));










        QPushButton *lock = new QPushButton("锁定");
        CDatabind *bindlock = new CDatabind();
        bindlock->SetUserData(i, 5);
        lock->setUserData(0, bindlock);
        ui->tableWidget->setCellWidget(i, 5, lock);
        connect(lock, SIGNAL(clicked()), this, SLOT(OnBtnLockdoor()));





void CDoorctl::OnBtnOpendoor()
{
    QPushButton *btn = (QPushButton *)sender();


    CDatabind *open = (CDatabind *)btn->userData(0);


    int row = open->m_nRow;
    int col = open->m_nCol;
    int m=0;
}




void CDoorctl::OnBtnLockdoor()
{
    QPushButton *btn = (QPushButton *)sender();


    CDatabind *open = (CDatabind *)btn->userData(0);


    int row = open->m_nRow;
    int col = open->m_nCol;
    int m=0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值