Results 1 to 3 of 3

Thread: mainwindow layout vs widget layout

  1. #1
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default mainwindow layout vs widget layout

    hi!
    I am new to Qt and was very happy when i created my first own widgets. Now i am trying to create something bigger using the idea of having "mainwindows" with toolbars, menus, etc.

    In Qwidgets I used the QGroupBox,QVBoxLayout,etc to arrange the design (buttons,sliders, Qwtplot areas,etc) of my widget layout. Now I tried to do the same with the mainwindow and it does not work. Reading the documentation I found out that in mainwindow class I cannot directly add Qwidgets, but I have to create a main widget and use the setCentralWidget(). I got a bit confused but just to get it right, the procedure should be like this?
    1. create mainwindow
    2. create main widget
    3. create several other smallerQwidgets
    4. use QGroupbox/QVBoxLayout to arrange smallerQwidgets in the main widget
    5. setCentralWidget(mainWidget)

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: mainwindow layout vs widget layout

    Just code / design your widgets as usual, and when you want to display them in QMainWindow call the "setCentralWidget(my_widget)" method.

    I am new to Qt and was very happy when i created my first own widgets
    Let "MyWidget" be your custom widget that made you happy. If you want to use it with QMainWindow you dont need to change anything in MyWidget, just call QMainWindow::setCentralWidget(my_widget), where my_widget is an instance of MyWidget.

    Of course if you want to use menus, toolbars ect. it will be convenient for you to create a subclass of QMainWindow, but I think you know that.

    Remember that QMainWindow is taking ownership of "my_widget", so when you change central widget to another one dont delete old pointer, object will be removed automatically.

    I think you can find some examples of QMainWindow usage in QT samples.

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

    fatecasino (14th December 2010)

  4. #3
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: mainwindow layout vs widget layout

    thanks,
    I started working on this with some inheritance reading.
    I have created a mainwindow
    I have created a widget
    I set the widget as central widget of the mainWindow
    and..
    I created a my2dplot class to plot 2d plots (worked)
    then
    I tried to copy bode example mouse tracking and zoomer and I ended up like this:

    http://www.qtcentre.org/threads/3695...mp-inheritance

Similar Threads

  1. Replies: 0
    Last Post: 12th December 2010, 05:09
  2. Replies: 2
    Last Post: 5th July 2010, 21:53
  3. Widget layout in GridLayout
    By Dato0011 in forum Qt Programming
    Replies: 8
    Last Post: 7th December 2009, 09:26
  4. Replies: 0
    Last Post: 25th May 2009, 10:00
  5. Replies: 7
    Last Post: 15th June 2007, 16:13

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.