"do you know about Qbuttongroup? That will no doubt help a lot.
http://doc.qt.nokia.com/stable/qbuttongroup.html
In addition, QButtonGroup can map between integers and buttons. You can assign an integer id to a button with setId(), and retrieve it with id(). The id of the currently checked button is available with checkedId(), and there is an overloaded signal buttonClicked() which emits the id of the button."
Ok, so I've created a QButtonGroup in my mainwindow.h file called QButtonGroup *guziki;
and
guziki = new QButtonGroup; in my Manager::pokazSlot function.
Then in every loop cycle I've added a button guziki->addButton(usun2,b); where b is the row's number.
I've tried connect(guziki->button(b),SIGNAL(clicked()),this,SLOT(usunPozycje()));
and after attempting to give indeks value indeks = guziki->checkedId(); i always get -1, like that button did't exist at all.
Can you give me an example how to pass this Id to my usunPozycje function?
Here's my present code:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
int Manager::pokazSlot()
{
int b=0;
int i;
QPushButton *usun = new QPushButton("Usun zaznaczone");
QStringList kolumny;
QDate today = QDate::currentDate();
QPushButton *usun2;
guziki = new QButtonGroup;
usun->setParent(tabela);
tabela->setColumnCount(3);
tabela->setColumnWidth(2,100);
tabela->setWindowTitle("Wszystkie terminy");
kolumny << "Data" << "Tresc" << "Usun zaznaczone" ;
tabela->setHorizontalHeaderLabels(kolumny);
for (i=-4000;i<4000;i++)
{
QDate all = today.addDays(i);
if(QFile::exists(all.toString() + ".txt"))
{
tabela->setRowCount(b+1);
QCheckBox *chkBox = new QCheckBox;
usun2 = new QPushButton("Delete",this);
QFile file(all.toString() + ".txt");
QTableWidgetItem *data = new QTableWidgetItem;
data->setText(all.toString());
tabela->setItem(b,0,data);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return 0;
QTextStream in(&file);
QTableWidgetItem *tresc = new QTableWidgetItem;
tresc->setText(in.readAll());
tabela->setItem(b,1,tresc);
guziki->addButton(usun2,b);
tabela->setCellWidget(b,2,guziki->button(b));
tabela->item(b,0)->setCheckState(chkBox->checkState());
tabela->resizeColumnToContents(1);
tabela->resizeColumnToContents(0);
tabela->resizeRowToContents(b);
connect(usun,SIGNAL(clicked()),this,SLOT(usunSlot()));
connect(guziki->button(b),SIGNAL(clicked()),this,SLOT(usunPozycje()));
b++;
}
}
int szer = tabela->columnWidth(0)+tabela->columnWidth(1)+17;
usun->setAutoDefault(false);
usun->move(szer,0);
tabela->setFixedSize(tabela->horizontalHeader()->length() + 60, tabela->verticalHeader()->length() + 60);
tabela->show();
return b;
}
void Manager::usunPozycje()
{
indeks = guziki->checkedId();
//indeks = Manager::pokazSlot();
QMessageBox::StandardButton czyszczenie;
czyszczenie = QMessageBox::warning(this, tr("Manager"), //wyswietl komunikat o niezapisanych zmianach w dokumencie
tr("Czy napewno skasowac %1?").arg(indeks),
QMessageBox::Yes | QMessageBox::Cancel);
}
|
Btw thanks for help, you guys are great