Dynamically creating push buttoms based on how many items are needed based on the amount
-
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.
-
i thought that would be the way to do it, hmm, guess not. LOL
-
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.
-
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
-
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); }
@
-
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.
-
!http://img.photobucket.com/albums/v238/adarksoul/UDK.png?t=1300880144(UDK content browser)!
here's a pic of the content browser
-
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
-
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.