[問題] RadioButton 觸發事件 (已解決)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
QT
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
radiobutton切換以及執行事件問題請教
餵入的資料(Input):
預期的正確結果(Expected Output):
想在GUI介面上做出單選紐,並能依照選紐而執行不同事件。
錯誤結果(Wrong Output):
目前介面上能做出單選紐,但按下按鈕後的反應不知道哪裡有誤
程式碼(Code):(請善用置底文網頁, 記得排版)
QGroupBox *buttonGrpBox = new QGroupBox("Function:");
buttonCheckBox = new QCheckBox("Choose Function");
buttonCheckBox->setChecked(false);
buttonEnabled= false;
connect(buttonCheckBox, SIGNAL(clicked()), this, SLOT(buttonCheckBoxClicked()));
A = new QRadioButton(tr("Function A"));
A -> setChecked(false);
AEnabled = false;
connect(A,SIGNAL(clicked()),this,SLOT(AClicked()));
B = new QRadioButton(tr("Function B"));
B -> setChecked(false);
BEnabled = false;
connect(B,SIGNAL(clicked()),this,SLOT(BClicked()));
C = new QRadioButton(tr("Function C"));
C -> setChecked(false);
CEnabled = false;
connect(C,SIGNAL(clicked()),this,SLOT(CClicked()));
QVBoxLayout *FunctionLayout = new QVBoxLayout;
FunctionLayout -> addWidget(buttonCheckBox);
FunctionLayout -> addWidget(A);
FunctionLayout -> addWidget(B);
FunctionLayout -> addWidget(C);
buttonGrpBox->setLayout(FuncitonLayout);
中略 .....
if(buttonEnabled)
{
if(AEnabled)
{
// DO A
}
else if(BEnabled)
{
// DO B
}
else if(CEnabled)
{
// DO C
}
else
{
// DO NOTHING
}
}
補充說明(Supplement):
只擷取部分code,該宣告的都有宣告,
原本以為會不會是radiobutton沒有設好,後來在三個Function做簡單的測試都是有反應的
目前用buttoncheckbox控制3個單選紐,按下buttonchexkbox後radiobutton才有作用,
在buttoncheckbox上的切換作用是成功的。
現在問題就是當我點選了buttonchackbox後,執行C->B->A都可以但是要再切換為B或C
就無法執行,即使把buttoncheckbox重新勾選依舊會卡在A
感覺是我迴圈寫法的問題:
目前寫法由下往上都可以,但要從上往下都不行。
先選C就可以C->B->A 或 C->A ,逆向不行。
先選B 就只能B->A,逆向不行。
先選A 就只卡在A。
懇請大大門解惑
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.28.223
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1441866783.A.CD6.html
※ 編輯: totemist (140.114.28.223), 09/10/2015 14:37:08
※ 編輯: totemist (140.114.28.223), 09/10/2015 14:46:04
推
09/10 15:35, , 1F
09/10 15:35, 1F
→
09/10 15:36, , 2F
09/10 15:36, 2F
→
09/10 15:37, , 3F
09/10 15:37, 3F
→
09/10 15:40, , 4F
09/10 15:40, 4F
→
09/10 15:40, , 5F
09/10 15:40, 5F
→
09/10 15:54, , 6F
09/10 15:54, 6F
→
09/10 15:54, , 7F
09/10 15:54, 7F
→
09/10 15:55, , 8F
09/10 15:55, 8F
我自己是有把isChecked()寫好,應該跟Y大您的意思一樣吧?
void AClicked() {
AEnabled = A->isChecked();
}
void BClicked() {
BEnabled = B->isChecked();
}
void CClicked() {
CEnabled = C->isChecked();
}
※ 編輯: totemist (140.114.28.223), 09/10/2015 16:20:58
→
09/10 16:50, , 9F
09/10 16:50, 9F
已經成功了~ 感謝Y大
主要就是要改用SIGNAL(toggled(bool)) 這樣即可~
※ 編輯: totemist (140.114.28.223), 09/10/2015 16:51:25
→
09/10 16:50, , 10F
09/10 16:50, 10F
→
09/10 16:56, , 11F
09/10 16:56, 11F
→
09/10 16:57, , 12F
09/10 16:57, 12F
→
09/10 16:58, , 13F
09/10 16:58, 13F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章