Results 1 to 3 of 3

Thread: Change QVBoxLayout index?

  1. #1
    Join Date
    Sep 2010
    Location
    Denmark
    Posts
    25
    Thanks
    10
    Thanked 3 Times in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Change QVBoxLayout index?

    Hi,
    I'm defining a palette through QPushButtons, as shown below:
    list_before.png
    If you press one of the buttons, and use arrowUp and arrowDown keys, you can traverse the list.

    If you for some reason want to rearrange the list you can do so by:
    1. Click one of the buttons
    2. Press 'A' if you want the button upwards, or 'Z' if you want it downwards

    This is the code:
    Qt Code:
    1. QLayoutItem *item = rightbox->takeAt(index);
    2. delete item;
    3. rightbox->insertWidget(index + 1, paletItems[index]);
    4. paletItems.swap(index,index+1);
    To copy to clipboard, switch view to plain text mode 
    rightbox is a QVBoxLayout, and paletitems is a QList containing the buttons.

    Here I have clicked the 'color 4' button, and moved it two places down.
    list_after.png
    It works fine except one thing:
    When you traverse the palette with the arrow-keys, it is af if the buttons has kept the original index in the layout?
    It jumps from 'color 3' to 'color 4', skipping the two colors in between. Very annoying.

    Why is this, and can I avoid it?
    Can I vhange the index of the layout-items?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,654
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Change QVBoxLayout index?

    I assume you are relying on the normal focus navigation for "traverse the list". You have rearranged the widgets on screen but they still carry their original tab order information.

  3. The following user says thank you to ChrisW67 for this useful post:

    davidlamhauge (27th April 2012)

  4. #3
    Join Date
    Sep 2010
    Location
    Denmark
    Posts
    25
    Thanks
    10
    Thanked 3 Times in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change QVBoxLayout index?

    Thank you! Works like a charm...

Similar Threads

  1. Change QTableView's index number displayed
    By rex in forum Qt Programming
    Replies: 0
    Last Post: 6th April 2011, 15:30
  2. Replies: 4
    Last Post: 2nd March 2011, 09:03
  3. QVBoxLayout to center
    By seltra in forum Newbie
    Replies: 2
    Last Post: 7th October 2010, 18:23
  4. QHBoxLayout & QVBoxLayout
    By damodharan in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2010, 14:13
  5. QScrollView with a QVboxlayout
    By rishid in forum Newbie
    Replies: 1
    Last Post: 18th January 2008, 16:14

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.