[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]
-
could you please tag your code using the "code" button above your textedit window?
That makes it much readable for us ;)What is your question exactly? What doesn't work for you as expected and what do you want instead?
-
@QVector<QPushButton*> v;
for (int a=0;a<10;a++)
v.push_back(new QPushButton);
@ -
I hope I understand you correctly
-
@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.
-
and how do we found which button is pressed??
thanks
-
[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
-
thank you all, all of you were great help. Now my problem is solved.