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. Dynamically creating push buttoms based on how many items are needed based on the amount
QtWS25 Last Chance

Dynamically creating push buttoms based on how many items are needed based on the amount

Scheduled Pinned Locked Moved General and Desktop
15 Posts 5 Posters 5.7k Views
  • 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.
  • P Offline
    P Offline
    ProgrammerAtHeart3344
    wrote on last edited by
    #1

    Ok, not sure if that makes any sense but here goes, basically I finally thought of a way to load all Ogre materials at once (or any resource for the matter) but now i can't seem to figure out the best way to create the buttons to hold the data in based on how many resources Ogre finds based on the materials here is the code so far:

    @MaterialSelection::MaterialSelection(QWidget* parent /* = 0 */)
    : QGraphicsView(parent)
    {
    pScene = new QGraphicsScene(this);

    pScene->setSceneRect(0,0,this->width(),this->height());
    

    QGraphicsProxyWidget* Proxy = new QGraphicsProxyWidget();

    MatMgr = Ogre::MaterialManager::getSingletonPtr();
    Ogre::MaterialManager::ResourceMapIterator resIter = MatMgr->getResourceIterator();

    while(resIter.hasMoreElements())
    {
    Ogre::MaterialManager::ResourceMapIterator::iterator i;

    for(i = resIter.begin(); i != resIter.end();++i)
    {
    pResHandle = i->first;
    pMaterialPointer = (Ogre::MaterialPtr)i->second;

    pMaterialPointer = Ogre::MaterialManager::getSingletonPtr()->getByHandle(pResHandle);

    for(unsigned short tech = 0; tech < pMaterialPointer->getNumTechniques(); ++tech)
    {
    this->MatTech = pMaterialPointer->getTechnique(tech);

       for(unsigned short passes = 0; passes < MatTech->getNumPasses(); ++passes)
       {
       MatPass = MatTech->getPass(passes);
       for(int numButtons = 0; numButtons < i->first; numButtons++)
       {
       QString matNames = QString("%1").arg(pMaterialPointer->getName().c_str());
       matButtons.reserve(numButtons);
       matButtons.push_back(new QPushButton(matNames));
       Proxy = pScene->addWidget(matButtons);
       
       }
       }
    

    }

    }
    }
    }
    @

    i thought maybe using a list would be a good idea, but doesn't seem like it, idk, any suggestings? remember i'm trying to create the buttons based on the amount of materials Ogre finds.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Max13
      wrote on last edited by
      #2

      Hi,

      I agree with your last thought. You could use a QList ?

      We all have started by asking questions. Then after some time, we can begin answering them.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        In my experience, it is not a great idea to use proxy widgets in QGraphicsView. They don't perform well. Is there a reason you use a QGraphicsView to put your buttons on?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          ProgrammerAtHeart3344
          wrote on last edited by
          #4

          i thought that would be the way to do it, hmm, guess not. LOL

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            The best approach to take, depends on what you actually want to achieve. That is not quite clear from your question. You talk about buttons to hold data, and then you suggest that a list might be an option.

            You can of course dynamically generate buttons to represent each material, but is that really what you want? Such a material list might perhaps be better presented as a list or a table. In that case, the model-view programming would be the way to go. Within that context, there are several ways to do that. If you let us know what you would like to achieve, we can help you to get there.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              ProgrammerAtHeart3344
              wrote on last edited by
              #6

              well, i kinda wanted to make a UDK content browser like system (UDK is in my opinion the best made engine around) and while i don't want to drive them out of business (unlikely) i'd like to get an editor going like theirs BSP and CSG still kinda confuse me but i'll get there when i get there

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Problem is, that that really doesn't tell me anything. I am not familiar with UDK, BSP or CSG. Could you post a screenshot of what you're after?

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vinb
                  wrote on last edited by
                  #8

                  cant you form a button in your 'while' loop and use an array to keep track?

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #9

                    sure, why not?

                    creatzing buttons is just new QPushButton
                    if you want to take pointer, i would do the following:

                    @
                    QVector<QPointer<QPushButton> > vec;

                    for(int i = 0; i < 10; ++i)
                    {
                        QPointer<QPushButton> p = new QPushButton(this);
                        myLayout->addWidget(p);
                       vec.append(p);
                    }
                    

                    @

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      Well, if you want to go that way, then I would extend the above a little bit...

                      @
                      QVector<QPointer<QPushButton> > vec;

                      QSignalMapper* smap = new QSignalMapper(this);
                      
                      for(int i = 0; i < 10; ++i)
                      {
                          QPointer<QPushButton> p = new QPushButton(this);
                          myLayout->addWidget(p);
                          vec.append(p);
                          connect (p, SIGNAL(clicked()), smap, SLOT(map()));
                          smap->setMapping(p, vec.count() -1);
                      }
                      
                      connect (smap, SIGNAL(mapped(int)), this, SLOT(buttonClicked(int)));
                      

                      @

                      That way, you can actually do some useful work when a button is clicked (though you of course have to actually implement a method called buttonClicked(int) ).

                      However, depending on the number of materials you wish to present, I would still considder a list first. You can also respond to selections in that list or (double) clicks on items in the list. Seems like a more scalable solution than just creating a load of buttons without knowing how many you might need. At least a list would be easy to expand (add filtering, sorting, etc) so it stays manageable for the user.

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        ProgrammerAtHeart3344
                        wrote on last edited by
                        #11

                        !http://img.photobucket.com/albums/v238/adarksoul/UDK.png?t=1300880144(UDK content browser)!

                        here's a pic of the content browser

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #12

                          Which part is the part you're trying to re-create?

                          First observation is that at least, there doesn't seem to be a big list of buttons somewhere in this interface...

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            giesbert
                            wrote on last edited by
                            #13

                            What I see is a list of checkable items. Did you want to create check boxes for them? There it would be easier to use a Model - view aproach with checkable items from the DataModel.

                            Nokia Certified Qt Specialist.
                            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              ProgrammerAtHeart3344
                              wrote on last edited by
                              #14

                              well, all the items in the bigger window are buttons based on the contenct in UDK's packages, least I assume they are buttons,when u click on one it high lights and when you double click it opens what ever window that button is associated with

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on last edited by
                                #15

                                No, I would not think they are buttons. They are items in an item view, with some custom rendering. Just like you get when you view a directory with images in your explorer in preview mode.

                                What you are after, I think, is a QListView (or possibly a QListWidget) set in icon mode.

                                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