Nested widgets, the inner widgets are not visible



  • Hi All,

    I have written a component that talks to the serial port. This component is made by using a QSplitter, and adding 2 buttins, a label and two LED indicators to it. When I then write the following I get 4 windows, 2 RS232's and two RS232monitor windows:

    rs232Rx = new RS232() //no parent
    rs232Tx = new RS232();
    myLog = new QTextBrowser();
    myHlayout = new QSplitter();
    myVlayout = new QSplitter();
    myVlayout->setOrientation(Qt::Vertical);
    myVlayout->addWidget(myLog);
    myVlayout->addWidget(rs232Rx);
    myHlayout->setParent(parent);
    myVlayout->show();
    rs232Rx->show();
    rs232Tx->show();
    

    When I write the following, I get 2 windows, both called Rs232Monitor, one with a splitter, and one blank window.

    rs232Rx = new RS232(this) //parent
    rs232Tx = new RS232(this);
    myLog = new QTextBrowser();
    myHlayout = new QSplitter();
    myVlayout = new QSplitter();
    myVlayout->setOrientation(Qt::Vertical);
    myVlayout->addWidget(myLog);
    myVlayout->addWidget(rs232Rx);
    myHlayout->setParent(parent);
    myVlayout->show();
    rs232Rx->show();
    rs232Tx->show();
    

    How can I change my code, so I get one window, with a QTextBrowser on top, and then 2 RS232 widgets side by side below it?
    Cheers,
    Cedric



  • [0_1523618792252_New folder.zip](Uploading 100%)



  • I have placed the above code on github:

    https://github.com/cdwijs/rs232monitor

    Cheers,
    Cedric



  • rs232Rx = new RS232(this);
    rs232Tx = new RS232(this);
    myLog = new QTextBrowser(this);
    myHlayout = new QSplitter(this);
    myVlayout = new QSplitter(this);
    myVlayout->setOrientation(Qt::Vertical);
    myHlayout->setOrientation(Qt::Horizontal);
    myHlayout->addWidget(rs232Rx);
    myHlayout->addWidget(rs232Tx);
    myVlayout->addWidget(myLog);
    myVlayout->addWidget(myHlayout);
    QHBoxLayout* mainLay=new QHBoxLayout(this);
    mainLay.addWidget(myVlayout);
    

  • Qt Champions 2017

    Hi
    If you do not give a Widget a parent or insert into other widget, it becomes
    a window if you show it.



  • Thanks everybody,
    It turns out that the constructor of the RS232 widgets has to be told myHlayout is the parent, and then also have to be added to myHlayout . Strange, but it now works:

        myLog = new QTextBrowser();
        myHlayout = new QSplitter();
        myVlayout = new QSplitter();
        rs232Rx = new RS232(myHlayout);
        rs232Tx = new RS232(myHlayout);
        myVlayout->setOrientation(Qt::Vertical);
        myHlayout->setOrientation(Qt::Horizontal);
        myHlayout->addWidget(rs232Rx);
        myHlayout->addWidget(rs232Tx);
        myVlayout->addWidget(myLog);
        myVlayout->addWidget(myHlayout);
        myVlayout->show();
    

    Cheers,
    Cedric


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.