PDA

View Full Version : QtKey looping



VireX
15th February 2007, 03:59
Well I want to loop through Qt::Key_0 to Qt::Key_9
Like adding a bunch of numbers in buttons:


for(int i = 0; i < 10; i++){
QPushButton* Nums[i] = new QPushButton(tr(i));
Nums[i]->setShortcut(0x30); // but i can't loop with hexes since there is no eval in C++
Nums[i]->setFixedWidth(25);
}

Any Ideas?

Brandybuck
15th February 2007, 05:38
There are only ten values, so do it sequentially, instead of in a loop.

VireX
15th February 2007, 06:24
But that's so anti-OO :O...

jpn
15th February 2007, 07:35
for (int i = Qt::Key_0; i <= Qt::Key_9; ++i) {
...
...->setShortcut(static_cast<Qt::Key>(i));
}

VireX
15th February 2007, 20:52
Well thanks! I can't test it yet, but i like it.