Two classes in the same mainwindow.cpp
-
@Nafab213 said in Two classes in the same mainwindow.cpp:
Ok I understood but I would like my Widget to be the centralwidget of my application.
How can I connect the Mywidget class with my Qmainwindow class. ?
Introduce me a sample code to better understand ..
Thank youOk I understood but I would like my Widget to be the centralwidget of my application.
How can I connect the Mywidget class with my Qmainwindow class. ?
Introduce me a sample code to better understand ..
Thank you -
Lets say for the sake of it, you did name it MyWidget
So in MainWindow.cpp
It would be like#include "mywidget.h" // include the new widget MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); setCentralWidget( new MyWidget(this) ); // create an instance and use as central ......
-
Exactly the example does not help me because they used only one: Mainwindow class without Qwidget for the Centralwidget. When I create the Qt class, the code is incomprehensible to me.
I would like to know if I can use a new C ++ class (the .h and .cpp file) to do the same thing.
And it will be at the beginning:class Mywidget : public QWidget
If so, what will be the connection code to use as Centralwidget of my mainwindow?
Thank you for the patience .. -
Hi
You can do as i shown higher up to have your own widget as central.
I assume you want to add features/code to it so its more than a normal QWidget.
( like moue Events or own paint function)
Else it would make little sense to subclass it.The key is the setCentralWidget to set it as central.
-
@Nafab213 said in Two classes in the same mainwindow.cpp:
Exactly the example does not help me because they used only one: Mainwindow class without Qwidget for the Centralwidget
Are you talking to @mrjj example or the one I pointed out? If the later, you may need to take a look again at the code:
MainWindow::MainWindow() : textEdit(new QPlainTextEdit) { setCentralWidget(textEdit); createActions(); ...
and QPlainTextEdit is, well, a QWidget after all... (QWidget -> QFrame -> QAbstractScrollArea -> QPlainTextEdit)
-
I'm afraid of getting lost if I use the Widget. I do not fully master C ++ yet.
I want to learn. You will give me a hand .. Thank youFirst stupid question:
Where do I start writing in the.cpp file ?#include "wigcen.h" #include "ui_wigcen.h" wigcen :: wigcen (QWidget * parent): QWidget (parent) ui (new Ui :: wigcen) { ui-> setupUi (this); // At this level ? } wigcen :: ~ wigcen () { delete ui; // At this level ? } or wigcen :: wigcen () { boutoncene = new QPushButton("C E N - P"); boutoncene->move(40, 50); boutoncene->setFont(QFont("Times New Roman", 16)); and more }
Thanks.....
-
@Pablo-J.-Rogina I'm talking about your example. They used Qplaintextedit as the centralwidget. This is my problem the Central Widget.
I would like an empty window like Widgetcentral.
I will add two buttons in the center of the window after.
How to do it ? -