KeineAhnung
1st May 2014, 10:05
Hi,
I have several group boxes (dynamical generated). The group boxes have been modified in a custom class and are now cards. I used the group box because with the border and the checkbox I only needed to add some content (image, text) to have my card.
That my program runs only one card is allowed to be active, like radio buttons. My plan was to create a signal that is sent to all boxes and tells them to turn off. The signal contains the sender index so that the sending box knows not to turn off as well. My problem is to connect the toggled(bool) signal from the QGroupBox with my custom signal. Can I somehow wire these two signals? Or asked differently how do I know where the toggled(bool) signal came from?
Here is the card class:
#ifndef SATIONCARD_H
#define SATIONCARD_H
#include <QLabel>
#include <QGroupBox>
#include <QLayout>
class StationCard : public QGroupBox{
Q_OBJECT
public:
StationCard();
QLabel *propLabel;
int index;
bool on;
public slots:
void turnOff(int actIndex);
signals:
void toggled(int index, bool on);
private:
};
#endif // SATIONCARD_H
#include "stationcard.h"
StationCard::StationCard(){
QHBoxLayout *layout = new QHBoxLayout;
propLabel = new QLabel();
layout->addWidget(propLabel, 10, Qt::AlignRight);
setLayout(layout);
on = isChecked();
if(on){
emit toggled(index, on);
emit turnOff(index);
}
}
void StationCard::turnOff(int actIndex){
if(actIndex != index){
setChecked(false);
}
}
And the connection in my main window:
int k = 0;
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 4; ++j){
CardVector[k] = new SationCard;
CardVector[k]->index = k;
QObject::connect(CardVector[k], SIGNAL(toggled(int, bool)), this, SLOT(on_stationCard_toggled(int, bool)));
ui->cardLayout->addWidget(enemyVector[k], i, j);
k++;
}
}
I have several group boxes (dynamical generated). The group boxes have been modified in a custom class and are now cards. I used the group box because with the border and the checkbox I only needed to add some content (image, text) to have my card.
That my program runs only one card is allowed to be active, like radio buttons. My plan was to create a signal that is sent to all boxes and tells them to turn off. The signal contains the sender index so that the sending box knows not to turn off as well. My problem is to connect the toggled(bool) signal from the QGroupBox with my custom signal. Can I somehow wire these two signals? Or asked differently how do I know where the toggled(bool) signal came from?
Here is the card class:
#ifndef SATIONCARD_H
#define SATIONCARD_H
#include <QLabel>
#include <QGroupBox>
#include <QLayout>
class StationCard : public QGroupBox{
Q_OBJECT
public:
StationCard();
QLabel *propLabel;
int index;
bool on;
public slots:
void turnOff(int actIndex);
signals:
void toggled(int index, bool on);
private:
};
#endif // SATIONCARD_H
#include "stationcard.h"
StationCard::StationCard(){
QHBoxLayout *layout = new QHBoxLayout;
propLabel = new QLabel();
layout->addWidget(propLabel, 10, Qt::AlignRight);
setLayout(layout);
on = isChecked();
if(on){
emit toggled(index, on);
emit turnOff(index);
}
}
void StationCard::turnOff(int actIndex){
if(actIndex != index){
setChecked(false);
}
}
And the connection in my main window:
int k = 0;
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 4; ++j){
CardVector[k] = new SationCard;
CardVector[k]->index = k;
QObject::connect(CardVector[k], SIGNAL(toggled(int, bool)), this, SLOT(on_stationCard_toggled(int, bool)));
ui->cardLayout->addWidget(enemyVector[k], i, j);
k++;
}
}