Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] how to generate dynamic array of buttons????
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 10.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TobbY
    wrote on last edited by
    #1

    @
    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]

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      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?

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Ruzik
        wrote on last edited by
        #3

        @QVector<QPushButton*> v;
        for (int a=0;a<10;a++)
        v.push_back(new QPushButton);
        @

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ruzik
          wrote on last edited by
          #4

          I hope I understand you correctly

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thisisbhaskar
            wrote on last edited by
            #5

            @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();
            @

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leon.anavi
              wrote on last edited by
              #6

              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.

              http://anavi.org/

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TobbY
                wrote on last edited by
                #7

                and how do we found which button is pressed??

                thanks

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  leon.anavi
                  wrote on last edited by
                  #8

                  [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

                  http://anavi.org/

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TobbY
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved