Results 1 to 2 of 2

Thread: How do I move a widget inside a grid Layout

  1. #1
    Join Date
    Mar 2006
    Location
    San Francisco, CA
    Posts
    23
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How do I move a widget inside a grid Layout

    Hello !

    I have a QFrame that has a QGridLayout. In grid cell 0,0 I have a QLabel
    that is left aligned and in cell 0,1 I have a QLabel that is right aligned.

    This frame is initially raised but I have it set up so you can click the
    frame and it will become sunken.

    When the frame switches to sunken I want to shift the QLabel in cell 0,0 a little
    bit to the right and down like buttons usually do. (aside: Maybe I could shift the
    whole grid but I was thinking the right aligned label in (0,1) might get clipped by
    the right edge.)

    OK so I tried the obvious .. saving the initial position of the QLabel
    when the frame is constructed with the line

    m_pInitialTitlePos = m_lblAssetTitle->pos();

    and then coding the below when I process the change in the frame's appearance ...

    Qt Code:
    1. if (state)
    2. {
    3. setFrameStyle(QFrame::Panel | QFrame::Raised);
    4. m_lblAssetTitle->move(m_pInitialTitlePos);
    5. }
    6. else
    7. {
    8. setFrameStyle(QFrame::Panel | QFrame::Sunken);
    9. m_lblAssetTitle->move(m_pInitialTitlePos + QPoint(10,10));
    10. }
    To copy to clipboard, switch view to plain text mode 

    but that does nothing.

    I am obviously way off on this one .. what is the right way to do things ?

    Thank you

    barnaby

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I move a widget inside a grid Layout

    Basically move() won't work because the layout won't allow it to. If you use layouts, you can't move widgets around. You are trying to do a very strange thing... You should either use buttons instead of labels (so that they behave like buttons, like you want them to) or subclass QLabel and implement the desired behaviour (shifting the contents) yourself. Or do both -- subclass one of button classes and implement your behaviour there.

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  3. Custom Widget inside a QVboxLayout
    By nemesis in forum Qt Programming
    Replies: 5
    Last Post: 25th June 2008, 14:55
  4. Move and resize with layout
    By waediowa in forum Qt Programming
    Replies: 0
    Last Post: 14th May 2008, 08:16
  5. How do I layout in a Grid?
    By DPinLV in forum Qt Tools
    Replies: 7
    Last Post: 10th August 2006, 01:37

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.