Results 1 to 3 of 3

Thread: How to combine two QWidgets(tracking widget with console) & show them in QMainwindow

  1. #1
    Join Date
    Apr 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default How to combine two QWidgets(tracking widget with console) & show them in QMainwindow

    My codes was derived from Qt example "Terminal".

    I added another class "trackingWidget", and it works very well as an independent widget from QMainWindow, where the console stays.

    Now I am trying to put my "trackingWidget" on the right side of console, and keep both of them inside QMainWindow; however, my "trackingWidget" disappeared.
    Here is my code:

    Qt Code:
    1. console = new Console;
    2. console ->setEnabled(false);
    3.  
    4. QGridLayout *centralLayout = new QGridLayout;
    5. centralLayout->addWidget(console , 0,0,1,1);
    6. centralLayout->addWidget(trackingWidget, 0,1,1,1);
    7. trackingWidget->resize(512,512);
    8. console ->resize(325,512);
    9.  
    10. QWidget *myCentralWidget = new QWidget;
    11. myCentralWidget->setLayout(centralLayout);
    12. setCentralWidget(myCentralWidget);
    To copy to clipboard, switch view to plain text mode 

    It is ok if I just add trackingWidget; however, once I add console, the trackingWidget would be crushed to nowhere like it has never been added.

    Is it possible to show multi-QWidgets with flexible sizes in one QWidget/QMainWindow?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to combine two QWidgets(tracking widget with console) & show them in QMainwin

    What is that trackingWidget?
    Is it a composition of other widgets?
    If so, is it properly layouted?
    If not, does it have a sizeHint()?

    Cheers,
    _

  3. #3
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to combine two QWidgets(tracking widget with console) & show them in QMainwin

    You'd better devise your UI in the Designer: this way you save yourself most of troubles with positioning and sizing widgets. Both the console and the trackingWidget are descendant of some standard parts of Qt: for example,the console is derived from QTextEdit most likely. Thus, create a main window in the Designer, add a QTextEdit, add a widget, which is the base of trackingWidget, set sizes, and put both in a horizontal layout. Set spacing of the layout and promote your widgets to console and the trackingWidget (all of this is made in the Designer). Save. Getting your UI to the screen is a matter of two simple calls: setupUi() and show().

Similar Threads

  1. Replies: 3
    Last Post: 14th June 2013, 12:22
  2. Replies: 8
    Last Post: 21st August 2012, 14:31
  3. Why does console show up =.=
    By xleniz in forum Qt Programming
    Replies: 3
    Last Post: 7th June 2012, 15:39
  4. QMainWindow and custom widget doesn't show
    By Peppy in forum Qt Programming
    Replies: 9
    Last Post: 26th December 2009, 16:09
  5. Tracking the movement of a top-level widget
    By mcb in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2009, 06:43

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.