June 23, 2011

TobbY TobbY
Lab Rat
208 posts

[SOLVED] how to generate dynamic array of buttons????

 

  1. QWidget *w=new QWidget;
  2.  
  3. QPushButton *p= new QPushButton [10];
  4.  
  5. QHBoxLayout *layout=new QHBoxLayout;
  6.  
  7. for(int i=0;i<10;i++){
  8.     layout->addWidget(p[i],Qt::AlignVCenter);
  9. }
  10. w->setLayout(layout);
  11. w->show();

[EDIT: code formatting, please wrap in @-tags and indent, Volker]

 Signature 

Gorilla..

8 replies

June 23, 2011

Eddy Eddy
Area 51 Engineer
1296 posts

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?

 Signature 

Qt Certified Specialist
Qt Ambassador

June 23, 2011

Ruzik Ruzik
Lab Rat
293 posts

  1. for (int a=0;a<10;a++)
  2.   v.push_back(new QPushButton);

June 23, 2011

Ruzik Ruzik
Lab Rat
293 posts

I hope I understand you correctly

June 23, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

  1. QWidget *w=new QWidget;
  2. QList<QPushButton*> buttonList;
  3. QHBoxLayout *layout=new QHBoxLayout;
  4. for(int i=0;i<10;i++)
  5. {
  6. QPushButton *p= new QPushButton;  
  7. buttonList.append(p);
  8. layout->addWidget(p,Qt::AlignVCenter);
  9. }
  10. w->setLayout(layout);
  11. w->show();

June 23, 2011

leon.anavi leon.anavi
Mad Scientist
1047 posts

The same topic is discussed here [developer.qt.nokia.com]

Additional nice hints might be layout classes such as QHBoxLayout [doc.qt.nokia.com], QVBoxLayout [doc.qt.nokia.com], etc and you should consider using QSignalMapper [doc.qt.nokia.com] for handling the signals.

 Signature 

http://anavi.org/

June 23, 2011

TobbY TobbY
Lab Rat
208 posts

and how do we found which button is pressed??

thanks

 Signature 

Gorilla..

June 23, 2011

leon.anavi leon.anavi
Mad Scientist
1047 posts

TobbY wrote:
and how do we found which button is pressed??

thanks

Using signals, as I mentioned in my previous post check class QSignalMapper [doc.qt.nokia.com]

 Signature 

http://anavi.org/

June 23, 2011

TobbY TobbY
Lab Rat
208 posts

thank you all, all of you were great help. Now my problem is solved.

 Signature 

Gorilla..

 
  ‹‹ Regarding Locking The File      Does anyone know any text to speech or speech to text conversion API’s??? ››

You must log in to post a reply. Not a member yet? Register here!