Results 1 to 5 of 5

Thread: How do I add a QGridlayout in a QMainwindow?

  1. #1
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How do I add a QGridlayout in a QMainwindow?

    I know how to add a QGridlayout in a QDialog but...

    Is it possible to ad a QGridlayout to a QMainwindow without subclassing/inheriting QMainwindow?
    How do I do this?

    Tnx

  2. #2
    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: How do I add a QGridlayout in a QMainwindow?

    Set the layout on a plain QWidget and set it as a central widget of the main window.

    Qt Code:
    1. QWidget* widget = new QWidget(mainWindow);
    2. widget->setLayout(gridLayout);
    3. mainWindow->setCentralWidget(widget);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    hakermania (20th October 2013)

  4. #3
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a QGridlayout in a QMainwindow?

    Tnx J-P Nurmi,

    It works, but...
    In the console I get the message:
    QLayout: Attempting to add QLayout "" to QMainWindow "", which already has a layout

    Despite this message it seems to work. Do you know I can prevent this message?

  5. #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: How do I add a QGridlayout in a QMainwindow?

    Quote Originally Posted by Teuniz View Post
    In the console I get the message:
    QLayout: Attempting to add QLayout "" to QMainWindow "", which already has a layout

    Despite this message it seems to work. Do you know I can prevent this message?
    Do you pass the main window as a parent for the QGridLayout? That means same than setting the layout on the main window. So either don't pass any parent or pass the central widget as a parent for the grid layout.
    J-P Nurmi

  6. #5
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a QGridlayout in a QMainwindow?

    Yep, you are right. Thanks a lot for your help J-P.

Similar Threads

  1. QMainWindow not receiving QResizeEvent
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2006, 06:11
  2. Dynamically Loading a QMainWindow?
    By natron in forum Newbie
    Replies: 10
    Last Post: 21st July 2006, 01:15
  3. QGridLayout
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 29th June 2006, 20:34
  4. Replies: 18
    Last Post: 22nd February 2006, 20:51
  5. QPixmap and QGridLayout
    By Talon_Karrde in forum Qt Programming
    Replies: 5
    Last Post: 22nd February 2006, 12:27

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.