Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Nested widgets, the inner widgets are not visible

Nested widgets, the inner widgets are not visible

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 768 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cdwijs
    wrote on last edited by cdwijs
    #1

    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cdwijs
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cdwijs
        wrote on last edited by
        #3

        I have placed the above code on github:

        https://github.com/cdwijs/rs232monitor

        Cheers,
        Cedric

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4
          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);
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

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

            1 Reply Last reply
            2
            • C Offline
              C Offline
              cdwijs
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved