Results 1 to 14 of 14

Thread: How to put 2 Widgets in a MainWindow ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to put 2 Widgets in a MainWindow ?

    Ok, if I change my mainwindow.cpp to this:
    Qt Code:
    1. mainwindow::mainwindow(QWidget*p)
    2. {
    3.  
    4. double *buffer=NULL;
    5.  
    6. plot=new Plot(100,250,buffer,buffer+1,this);
    7. data = new Data(250,buffer,this);
    8.  
    9. QVBoxLayout* layout = new QVBoxLayout(this);
    10. data->on_watcher();
    11. }
    To copy to clipboard, switch view to plain text mode 

    I see my QTableWidget in the left corner, and no plot at all...

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to put 2 Widgets in a MainWindow ?

    In the code from last post you didn't add the widgets to layout.

    Did you did that in your actual project? (You still need to do that)

    Qt Code:
    1. mainwindow::mainwindow(QWidget*p)
    2. {
    3.  
    4. double *buffer=NULL;
    5.  
    6. plot=new Plot(100,250,buffer,buffer+1,p);
    7. data = new Data(250,buffer,p);
    8.  
    9. QVBoxLayout* layout = new QVBoxLayout(this);
    10.  
    11. layout->addWidget(plot);
    12. layout->addWidget(data);
    13.  
    14. //Start of on_watcher
    15. data->on_watcher();
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to put 2 Widgets in a MainWindow ?

    oopps , I meant:

    Qt Code:
    1. mainwindow::mainwindow(QWidget*p)
    2. {
    3.  
    4. double *buffer=NULL;
    5.  
    6. plot=new Plot(100,250,buffer,buffer+1,this);
    7. data = new Data(250,buffer,this);
    8.  
    9. QVBoxLayout* layout = new QVBoxLayout(this);
    10.  
    11. layout->addWidget(plot);
    12. layout->addWidget(data);
    13.  
    14. data->on_watcher();
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to put 2 Widgets in a MainWindow ?

    Are you sure this is what you want
    Qt Code:
    1. plot=new Plot(100,250,buffer,buffer+1,this); // the buffer pointer is NULL and you are adding 1 to that???
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jun 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to put 2 Widgets in a MainWindow ?

    That's not the problem....buffer acts as a chart...everything works fine in there....when I do a setCentralWidget(plot) I see my plot and my program does what it's supposed to..
    Altought, now, I want to add a QTableWidget, which is created and filled in my data class, and I don't know how to put both on my MainWindow

  6. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to put 2 Widgets in a MainWindow ?

    Do you get some warnings about mainWindow allready have a layout?

    Try to add a QWidget *test = new QWidget(0); make it the parent of the layout QVBoxLayout* layout = new QVBoxLayout(test); and setCentralWidget(test);

Similar Threads

  1. Replies: 5
    Last Post: 18th April 2010, 23:31
  2. resizing widgets when user resizes mainwindow
    By Mystical Groovy in forum Qt Programming
    Replies: 13
    Last Post: 21st December 2009, 00:03
  3. Replies: 2
    Last Post: 31st July 2009, 09:18
  4. Child Widgets In MainWindow
    By RY in forum Newbie
    Replies: 3
    Last Post: 4th October 2008, 08:39
  5. scrolled widgets containers in Mainwindow
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2006, 14:40

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.