Have a separate window as the child
-
-
@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. " -
@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 isMltpDlgs2
, why don't you subclass fromQDialog
? That will show you what you want.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!!
@jsulm Probably a new class (for the second UI) is not correct and for that purpose I need to use something else. Right?
-
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!!
@jsulm Probably a new class (for the second UI) is not correct and for that purpose I need to use something else. Right?
@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? -
@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?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? -
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?@tomy Because the default
windowFlags
for QDialog isQt::Dialog
, that indicatesQt::Window
.
(Qt::Dialog
= 0x00000002 |Qt::Window
)
If you want a widget to both having a parent and being a top-level window, you must haveQt::Window
set inwindowFlags
.
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)
-
@tomy Because the default
windowFlags
for QDialog isQt::Dialog
, that indicatesQt::Window
.
(Qt::Dialog
= 0x00000002 |Qt::Window
)
If you want a widget to both having a parent and being a top-level window, you must haveQt::Window
set inwindowFlags
.
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)
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. :)
-
@tomy Because the default
windowFlags
for QDialog isQt::Dialog
, that indicatesQt::Window
.
(Qt::Dialog
= 0x00000002 |Qt::Window
)
If you want a widget to both having a parent and being a top-level window, you must haveQt::Window
set inwindowFlags
.
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)
-
MltpDlgs2::MltpDlgs2(QWidget *parent) : QWidget(parent, Qt::Window)
What does that
Qt::Window
above mean if you want to say in simple language, please? -
MltpDlgs2::MltpDlgs2(QWidget *parent) : QWidget(parent, Qt::Window)
What does that
Qt::Window
above mean if you want to say in simple language, please?@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!