[SOLVED] how to generate dynamic array of buttons????
-
@
QWidget *w=new QWidget;QPushButton *p= new QPushButton [10];
QHBoxLayout *layout=new QHBoxLayout;
for(int i=0;i<10;i++){
layout->addWidget(p[i],Qt::AlignVCenter);
}
w->setLayout(layout);
w->show();
@[EDIT: code formatting, please wrap in @-tags and indent, Volker]
-
@QWidget w=new QWidget;
QList<QPushButton> buttonList;
QHBoxLayout *layout=new QHBoxLayout;
for(int i=0;i<10;i++)
{
QPushButton *p= new QPushButton;
buttonList.append(p);
layout->addWidget(p,Qt::AlignVCenter);
}
w->setLayout(layout);
w->show();
@ -
The same topic is discussed "here":http://developer.qt.nokia.com/forums/viewthread/5813
Additional nice hints might be layout classes such as "QHBoxLayout ":http://doc.qt.nokia.com/latest/qhboxlayout.html, "QVBoxLayout":http://doc.qt.nokia.com/latest/qvboxlayout.html, etc and you should consider using "QSignalMapper":http://doc.qt.nokia.com/latest/qsignalmapper.html for handling the signals.
-
[quote author="TobbY" date="1308816265"]and how do we found which button is pressed??
thanks[/quote]
Using signals, as I mentioned in my previous post check class "QSignalMapper":http://doc.qt.nokia.com/latest/qsignalmapper.html