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. Have a separate window as the child
Forum Updated to NodeBB v4.3 + New Features

Have a separate window as the child

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 1.9k 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.
  • tomyT tomy

    @jsulm

    Sorry, I must have said "inside it" (not as a separate UI).

    B Offline
    B Offline
    Bonnie
    wrote on last edited by Bonnie
    #4

    @tomy That is a widget which has a parent normally performs.
    Do you mean you want it to be a top-level window, but with a parent set?
    Since the class name is MltpDlgs2, why don't you subclass from QDialog? That will show you what you want.

    tomyT 1 Reply Last reply
    4
    • tomyT tomy

      @jsulm

      Sorry, I must have said "inside it" (not as a separate UI).

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #5

      @tomy Well, it does exactly what you asked it to do. See @Bonnie post.
      You can also easily find this information in the documentation (https://doc.qt.io/qt-5/qwidget.html#QWidget):
      "If parent is nullptr, the new widget becomes a window. If parent is another widget, this widget becomes a child window inside parent. "

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • B Bonnie

        @tomy That is a widget which has a parent normally performs.
        Do you mean you want it to be a top-level window, but with a parent set?
        Since the class name is MltpDlgs2, why don't you subclass from QDialog? That will show you what you want.

        tomyT Offline
        tomyT Offline
        tomy
        wrote on last edited by tomy
        #6

        @Bonnie

        Do you mean you want it to be a top-level window, but with a parent set?

        Yes, I think.

        Since the class name is MltpDlgs2, why don't you subclass from QDialog? That will show you what you want.

        I wanted, but there isn't such a base class on the list!!

        Untitled.png

        @jsulm Probably a new class (for the second UI) is not correct and for that purpose I need to use something else. Right?

        B 1 Reply Last reply
        0
        • tomyT tomy

          @Bonnie

          Do you mean you want it to be a top-level window, but with a parent set?

          Yes, I think.

          Since the class name is MltpDlgs2, why don't you subclass from QDialog? That will show you what you want.

          I wanted, but there isn't such a base class on the list!!

          Untitled.png

          @jsulm Probably a new class (for the second UI) is not correct and for that purpose I need to use something else. Right?

          B Offline
          B Offline
          Bonnie
          wrote on last edited by Bonnie
          #7

          @tomy ...Do you think all of us can only subclass those several classes?
          Use that <Custom> and you can subclass any class by filling in the empty line edit...
          This is only a wizard...you can even create a new class without using it.
          Though I usually select the QWidget as base class and then modify it to another widget class after the files are auto generated.
          Like now, you can just modify your existing code, I'll only post the lines you need to change:
          MltpDlgs2.h:

          #include <QDialog>
          
          class MltpDlgs2 : public QDialog
          

          MltpDlgs2.cpp:

          MltpDlgs2::MltpDlgs2(QWidget *parent) : QDialog(parent)
          

          P.S. Then how did you create MltpDlgs1 class in the first place?

          tomyT 1 Reply Last reply
          3
          • B Bonnie

            @tomy ...Do you think all of us can only subclass those several classes?
            Use that <Custom> and you can subclass any class by filling in the empty line edit...
            This is only a wizard...you can even create a new class without using it.
            Though I usually select the QWidget as base class and then modify it to another widget class after the files are auto generated.
            Like now, you can just modify your existing code, I'll only post the lines you need to change:
            MltpDlgs2.h:

            #include <QDialog>
            
            class MltpDlgs2 : public QDialog
            

            MltpDlgs2.cpp:

            MltpDlgs2::MltpDlgs2(QWidget *parent) : QDialog(parent)
            

            P.S. Then how did you create MltpDlgs1 class in the first place?

            tomyT Offline
            tomyT Offline
            tomy
            wrote on last edited by tomy
            #8

            @Bonnie

            Then how did you create MltpDlgs1 class in the first place?

            By inheriting from QLabel. But for the second class that base class doesn't exist and had to manually inherit from QLabel.

            But why this works now, please?
            I mean what's the difference between those two widgets (QWidget& QDialog) for my project that makes that difference?

            B 1 Reply Last reply
            0
            • tomyT tomy

              @Bonnie

              Then how did you create MltpDlgs1 class in the first place?

              By inheriting from QLabel. But for the second class that base class doesn't exist and had to manually inherit from QLabel.

              But why this works now, please?
              I mean what's the difference between those two widgets (QWidget& QDialog) for my project that makes that difference?

              B Offline
              B Offline
              Bonnie
              wrote on last edited by Bonnie
              #9

              @tomy Because the default windowFlags for QDialog is Qt::Dialog, that indicates Qt::Window.
              ( Qt::Dialog = 0x00000002 | Qt::Window)
              If you want a widget to both having a parent and being a top-level window, you must have Qt::Window set in windowFlags.
              So if you don't change your code according to my last post, you can also have it done by changing:
              MltpDlgs2.cpp:

              MltpDlgs2::MltpDlgs2(QWidget *parent) : QWidget(parent, Qt::Window)
              
              tomyT 2 Replies Last reply
              2
              • B Bonnie

                @tomy Because the default windowFlags for QDialog is Qt::Dialog, that indicates Qt::Window.
                ( Qt::Dialog = 0x00000002 | Qt::Window)
                If you want a widget to both having a parent and being a top-level window, you must have Qt::Window set in windowFlags.
                So if you don't change your code according to my last post, you can also have it done by changing:
                MltpDlgs2.cpp:

                MltpDlgs2::MltpDlgs2(QWidget *parent) : QWidget(parent, Qt::Window)
                
                tomyT Offline
                tomyT Offline
                tomy
                wrote on last edited by tomy
                #10

                @Bonnie

                Qh, that's rather too advanced for me at least for the time being. So for now I stick to the prior version (inheriting from QLabel manually). Perhaps some time in the future I will need to get used to those window and flags more. :)

                PS: This, too, worked, thanks. :)

                1 Reply Last reply
                0
                • B Bonnie

                  @tomy Because the default windowFlags for QDialog is Qt::Dialog, that indicates Qt::Window.
                  ( Qt::Dialog = 0x00000002 | Qt::Window)
                  If you want a widget to both having a parent and being a top-level window, you must have Qt::Window set in windowFlags.
                  So if you don't change your code according to my last post, you can also have it done by changing:
                  MltpDlgs2.cpp:

                  MltpDlgs2::MltpDlgs2(QWidget *parent) : QWidget(parent, Qt::Window)
                  
                  tomyT Offline
                  tomyT Offline
                  tomy
                  wrote on last edited by tomy
                  #11

                  @Bonnie

                  MltpDlgs2::MltpDlgs2(QWidget *parent) : QWidget(parent, Qt::Window)

                  What does that Qt::Window above mean if you want to say in simple language, please?

                  B JonBJ 2 Replies Last reply
                  0
                  • tomyT tomy

                    @Bonnie

                    MltpDlgs2::MltpDlgs2(QWidget *parent) : QWidget(parent, Qt::Window)

                    What does that Qt::Window above mean if you want to say in simple language, please?

                    B Offline
                    B Offline
                    Bonnie
                    wrote on last edited by Bonnie
                    #12

                    @tomy This is where you pass the windowFlags to the QWidget constructor.
                    A Qt::Window means I want this widget to be a top-level window, no matter with or without a parent.

                    1 Reply Last reply
                    1
                    • tomyT tomy

                      @Bonnie

                      MltpDlgs2::MltpDlgs2(QWidget *parent) : QWidget(parent, Qt::Window)

                      What does that Qt::Window above mean if you want to say in simple language, please?

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #13

                      @tomy
                      You can read through what all the window flags are at https://doc.qt.io/qt-5/qt.html#WindowType-enum, and there is even an example you can run at https://doc.qt.io/qt-5/qtwidgets-widgets-windowflags-example.html which lets you click to see what each window flag does in practice!

                      1 Reply Last reply
                      2

                      • Login

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