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. Subwindows on MainWindow
Forum Updated to NodeBB v4.3 + New Features

Subwindows on MainWindow

Scheduled Pinned Locked Moved General and Desktop
qtwidgets
5 Posts 2 Posters 5.8k Views 1 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.
  • Lays147L Offline
    Lays147L Offline
    Lays147
    wrote on last edited by Lays147
    #1

    Hi folks!
    I am developing this new application, which is a system for medical offices. I have a doubt. I want to load the entries and queries in my main application window. Is there a way to make these sub-windows in widgets (UI's) separate and call them inside the main window? If yes, what should I do?
    Thanks!

    Lays Rodrigues
    Newby on Qt - Learning always!
    Using QT 5.7
    ArchLinux

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AlexRoot
      wrote on last edited by AlexRoot
      #2

      Hi,
      what exactly do you want? Seperate windows?

      QWidget *widget = new QWidget;
      widget->show();
      

      and you have a new window.
      To add subwidgets to your main window you can add it to a layout like this in your mainwindow:

      // Set layout
      QHBoxLayout *layout = new QHBoxLayout;
      this->setLayout(layout);
      
      // Set layout in QWidget
      QWidget *widget = new QWidget();
      layout->addWidget(widget);
      

      Anything else you want to know?

      Cheers
      AlexRoot

      Lays147L 1 Reply Last reply
      1
      • A AlexRoot

        Hi,
        what exactly do you want? Seperate windows?

        QWidget *widget = new QWidget;
        widget->show();
        

        and you have a new window.
        To add subwidgets to your main window you can add it to a layout like this in your mainwindow:

        // Set layout
        QHBoxLayout *layout = new QHBoxLayout;
        this->setLayout(layout);
        
        // Set layout in QWidget
        QWidget *widget = new QWidget();
        layout->addWidget(widget);
        

        Anything else you want to know?

        Cheers
        AlexRoot

        Lays147L Offline
        Lays147L Offline
        Lays147
        wrote on last edited by
        #3

        @AlexRoot isnt workin, i get this error:

        QWidget::setLayout: Attempting to set QLayout "" on SimpleDental "SimpleDental", which already has a layout
        The program has unexpectedly finished.
        

        Lays Rodrigues
        Newby on Qt - Learning always!
        Using QT 5.7
        ArchLinux

        1 Reply Last reply
        0
        • Lays147L Offline
          Lays147L Offline
          Lays147
          wrote on last edited by Lays147
          #4

          I did in this way:

          pacientesCad *p = new pacientesCad;
              QHBoxLayout *b = new QHBoxLayout;
              ui->widget->setLayout(b);
              b->addWidget(p);
          

          And it works, is that all correct? Well, it works on the first case, when i try load another widget, i cant, because the widget have a layout loaded, but i try this:
          ui->slaveWidget->layout()->deleteLater();
          But the same error above shows up.
          Any tips?

          Lays Rodrigues
          Newby on Qt - Learning always!
          Using QT 5.7
          ArchLinux

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AlexRoot
            wrote on last edited by
            #5

            Hi Lays,
            when you already have a layout set, you don't need to create a new one.
            Just access your existing Layout with the layout() function.
            In general every QWidget has its own layout (there are different kinds of layouts) and you can add widgets to them.
            So if you want to add a widget to your QMainWindows layout you can call inside your main windows code something like this:
            this->layout()->addWidget(new Widget);
            For further information please read http://doc.qt.io/qt-4.8/layout.html.

            Greetings
            AlexRoot

            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