Thanks for your answers wysota and Steve.
I made the MainWindow and the other Widget using Qt Desginer.
Now, I have MainWindow.ui and Editor.ui.
The MainWindow have a Menu, and it will contain a dock widget with the editor widget.
This the MainWindow.h code:
#include <QMainWindow>
#include <QDockWidget>
#include "ui_MainWindow.h"
#include "editor.h"
class MainWindow
: public QMainWindow,
private Ui
::MainWindow{
Q_OBJECT
public:
QDockWidget* dock;
// the dock that will contain the editor widget Editor* editor; //the widget with the textedit
MainWindow
(QWidget* parent
= 0, Qt
::WFlags fl
= 0 );
~MainWindow();
public slots:
};
#include <QMainWindow>
#include <QDockWidget>
#include "ui_MainWindow.h"
#include "editor.h"
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
QDockWidget* dock; // the dock that will contain the editor widget
Editor* editor; //the widget with the textedit
MainWindow(QWidget* parent = 0, Qt::WFlags fl = 0 );
~MainWindow();
public slots:
};
To copy to clipboard, switch view to plain text mode
And this is the MainWindow.cpp
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget* parent, Qt
::WFlags fl
){
setupUi(this);
editor = new Editor(dock);
dock->setWidget(editor);
addDockWidget(Qt::RightDockWidgetArea, dock);
}
#include "mainwindow.h"
MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl)
: QMainWindow( parent, fl ), Ui::MainWindow()
{
setupUi(this);
dock = new QDockWidget(tr("Editor"),this);
editor = new Editor(dock);
dock->setWidget(editor);
addDockWidget(Qt::RightDockWidgetArea, dock);
}
To copy to clipboard, switch view to plain text mode
This the code of the Editor, may be will be useful.
#include <QWidget>
#include "ui_editor.h"
class Editor
: public QWidget,
private Ui
::Form{
Q_OBJECT
public:
Editor
(QWidget* parent
= 0, Qt
::WFlags fl
= 0 );
~Editor();
public slots:
};
#include <QWidget>
#include "ui_editor.h"
class Editor : public QWidget, private Ui::Form
{
Q_OBJECT
public:
Editor(QWidget* parent = 0, Qt::WFlags fl = 0 );
~Editor();
public slots:
};
To copy to clipboard, switch view to plain text mode
Editor.cpp
#include "editor.h"
Editor
::Editor(QWidget* parent, Qt
::WFlags fl
): QWidget( parent, fl
), Ui
::Form() {
setupUi(this);
}
#include "editor.h"
Editor::Editor(QWidget* parent, Qt::WFlags fl)
: QWidget( parent, fl ), Ui::Form()
{
setupUi(this);
}
To copy to clipboard, switch view to plain text mode
When I compile the project it works fine, without errors, but the MainWindow doesn't have the docked widget inside. What I'm doing wrong?
I only got the MainWindow with the Menu. The dock widget doesn't exist.
thanks!
Bookmarks