Results 1 to 5 of 5

Thread: Please help me in layout coding

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Please help me in layout coding

    I was asked in an interview to add a pushbutton on the window which should appear on the bottom-right corner of the window. I told him we can do it with setGeometry(..) function. But he wasn't satisfied. He asked me to do it with layouts. My partial answer to him was to add the button in the bottom cell of the QVBoxlayout, but that will not show the button on the desired corner of the window.
    Please help me with the code for this.

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

    Default Re: Please help me in layout coding

    QGridLayout might be one way.

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

    Default Re: Please help me in layout coding

    ... another would be a QVBoxLayout like you said, containing a QHBoxLayout with a spacer and the button. A geek solution could be to use QDialogButtonBox.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Please help me in layout coding

    Thanks for your answer, but can you please help me how to the code for this?

  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Please help me in layout coding

    Here is one way

    Qt Code:
    1. QWidget* widget = new QWidget(this);
    2. QGridLayout* layout = new QGridLayout(widget);
    3. QPushButton* button = new QPushButton("Bottom Left Corner", this);
    4. layout->addWidget(button);
    5. layout->setAlignment(Qt::AlignBottom | Qt::AlignRight);
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Using gui objectNames when coding
    By The physicist in forum Newbie
    Replies: 21
    Last Post: 19th December 2010, 22:50
  2. Coding a game with Qt
    By seltra in forum Qt Programming
    Replies: 5
    Last Post: 5th October 2010, 20:49
  3. Replies: 6
    Last Post: 29th January 2010, 23:56
  4. Replies: 0
    Last Post: 18th July 2009, 13:07
  5. What is your coding style ??
    By guestgulkan in forum General Discussion
    Replies: 9
    Last Post: 29th May 2006, 09:22

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.