Results 1 to 5 of 5

Thread: QtKey looping

  1. #1
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QtKey looping

    Well I want to loop through Qt::Key_0 to Qt::Key_9
    Like adding a bunch of numbers in buttons:
    Qt Code:
    1. for(int i = 0; i < 10; i++){
    2. QPushButton* Nums[i] = new QPushButton(tr(i));
    3. Nums[i]->setShortcut(0x30); // but i can't loop with hexes since there is no eval in C++
    4. Nums[i]->setFixedWidth(25);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Any Ideas?

  2. #2
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QtKey looping

    There are only ten values, so do it sequentially, instead of in a loop.

  3. #3
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtKey looping

    But that's so anti-OO :O...

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QtKey looping

    Qt Code:
    1. for (int i = Qt::Key_0; i <= Qt::Key_9; ++i) {
    2. ...
    3. ...->setShortcut(static_cast<Qt::Key>(i));
    4. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtKey looping

    Well thanks! I can't test it yet, but i like it.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.