Results 1 to 2 of 2

Thread: Find row that object occupies in grid layout

  1. #1
    Join Date
    Sep 2009
    Posts
    41
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Find row that object occupies in grid layout

    Suppose I have multiple widgets in a grid layout. How do I find what row and column a particular object occupies? It's easy to find an object if you know the row and column using itemAt(), but I would like to do the reverse: int row = my_object->isAtRow() or something like that. Thanks for your help!

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Find row that object occupies in grid layout

    QGridLayout::indexOf(QWidget*) returns an integer index that corresponds to a row-major traversal of grid layout. You can get the row by dividing the index by the width of the grid, and the column by taking the modulus.

    Note that this assumes none of your widgets span more than a single cell, although you can still put together a workable scheme if you have detailed knowledge of such things in advance.

    See also QGridLayout::getItemPosition() once you have the index.
    Last edited by SixDegrees; 2nd June 2010 at 22:30.

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

    Ishmael (2nd June 2010)

Similar Threads

  1. Grid Layout problem
    By succorguy in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2009, 00:01
  2. qdirmodel in grid layout
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 27th July 2008, 09:26
  3. How do I layout in a Grid?
    By DPinLV in forum Qt Tools
    Replies: 7
    Last Post: 10th August 2006, 02:37
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  5. Grid layout
    By nupul in forum Qt Programming
    Replies: 7
    Last Post: 21st April 2006, 22:15

Tags for this Thread

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.