Qt的禁用动态按钮 [英] Qt disabling dynamic buttons

查看:955
本文介绍了Qt的禁用动态按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图关闭用户pviously选择按钮$ P $

I am trying to disable button previously chosen by user

void pracownik2::on_pushButton_4_clicked(){

this->setWindowTitle("EKRAN");
QWidget *centralWidget = new QWidget;
        int licznik=1;
        QString licz;
        //QString kolumny = ui->lineEdit->text();
        //QString wiersze = ui->lineEdit_2->text();
        miejsca2 = ui->lineEdit_3->text().toInt();
        //QPushButton *button[wiersze.toInt()][kolumny.toInt()];
        QPushButton *button[3][6];

        QGridLayout *controlsLayout = new QGridLayout;
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<6;j++)
            {
                    licz = QString::number(licznik);
                    licznik++;
                    button[i][j] = new QPushButton(licz);
                    button[i][j]->setCheckable(1);
                        if(tab[i][j]==1)
                            button[i][j]->setEnabled(false);
                    controlsLayout->addWidget(button[i][j], i, j);
            }
        }

        QPushButton *okej = new QPushButton("Zatwierdź");
        QPushButton *anul = new QPushButton("Anuluj");

        controlsLayout->addWidget(okej, 3, 0);
        controlsLayout->addWidget(anul, 3, 1);

        controlsLayout->setHorizontalSpacing(0);
        controlsLayout->setVerticalSpacing(0);
        centralWidget->setLayout(controlsLayout);

        setCentralWidget(centralWidget);



        for(int i=0;i<3;i++)
        {
            for(int j=0;j<6;j++)
            {
                    connect(button[i][j],SIGNAL(toggled(bool)),this,SLOT(tescik(bool)));
            }
        }



        connect(anul,SIGNAL(clicked()),this,SLOT(close()));

        connect(okej,SIGNAL(clicked()),this,SLOT(okay2()));}

void pracownik2::tescik(bool t){
    if (t)
{
    tab[i][j]=1;
    miejsca++;
}
else
{
    tab[i][j]=0;
    miejsca--;
}}

但我的'tescik'函数不知道什么'我'和'J'是,该项目将无法编译,我的问题是,如何让检查按钮设定值1数组中,并选中它恢复到0我想我必须编辑连接行,但我不知道如何

but my 'tescik' function doesn't know what 'i' and 'j' are and the project won't compile, my question is how to make checked button set value 1 in the array and unchecked restore it to 0. I guess I have to edit 'connect' line but I have no idea how

@EDIT
我试图让这一行

@EDIT I am trying to make this line

connect(button[i][j],SIGNAL(toggled(bool)),this,SLOT(tescik(bool,int i,int j)));

通的i和当前按钮的J的功能,但它不工作

pass 'i' and 'j' of current button to function but it doesn't work

推荐答案

我会成立i和j每个按钮的属性:

I would set i and j as properties of each button:

...
button[i][j]->setProperty("i", i);
button[i][j]->setProperty("j", j);
...

然后在tescik()获取发件人和负载i和j:

Then in tescik() get the sender and load i and j:

void pracownik2::tescik(bool t) {
   QObject * pSender = sender();
   int i = pSender->property("i").toInt();
   int j = pSender->property("j").toInt();

   if (t) {
   ...

这篇关于Qt的禁用动态按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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