PDA

View Full Version : Arrays With Designer?



Erich
19th August 2010, 16:24
Hi folks,

does anyone know, how do create a QPushButton array with qDesigner?

Example:

int cnt = 20;
QPushButton *butt[cnt];
for ( int i = 0; i < cnt; i++) {
butt[i] = new QPushButton("");
....
}

Can I do such a thing with Designer too?

Thanks for any answers!

Erich

Lykurg
19th August 2010, 16:36
the designer is only a tool for designing GUIs. You can't do this with designer. Why do you need it? You can get all push buttons later via qFindChild() or if you need an array for signal/slots normally a QSignalMapper is better than a list.

squidge
19th August 2010, 18:54
Tell us what you are trying to do first, and we may be able to tell you an easier method.

Erich
19th August 2010, 21:39
Hallo,

thanks for your answers!

I wrote a sudoku solver in C++ and now I'll try to give it a GUI. The solver works on an array of fields, each holding one number of a sudoku game. (Every field is an array by itself, so I have 3 dimensions.) My Problem is not, to write the GUI by hand. I look for a solution with QDesigner and I would like to include a 9x9 array of appropriate widgets in a QDesigner form.

Erich

squidge
19th August 2010, 22:11
One way of doing that would be to drop an appropriate widget on the form (eg. a QLineEdit) and then using copy/paste to give 9 of that objects. Then you could copy those nine and paste 9 times to give you your 9x9 array. You can then easily place these into an array of pointers (to call there methods) as you'll know the names from what you type into the designer. To manage the signals, you can use a QSignalMapper which will inform you which widget the signal came from.

There are other ways, but thats the first way that comes to mind if you want to use designer. Doing it in code wouldn't be much more difficult - you would just create the objects dynamically.

Erich
20th August 2010, 15:53
Many thanks for your answers!

I found an easy way by myself: I coded the array as a subclass (QFrame). Then I put a QFrame in the designer and used it as a placeholder for my own object. Now i have the array with propper indices (codet by hand) and the complete GUI in designer. It works!

Erich