Re: Help with Docked Widget!
So maybe first clearly state what you want and then we'll try to help you. Do you actually want to use a dock widget or is it just an example of some behaviour you want?
Re: Help with Docked Widget!
Thanks for your answer wysota.
Well, I want to make an application with a textedit and a docket widget to the right side of the Window, the docked will contain a widget with some buttons, and the user will be able to hide, move, and close the docket.
Re: Help with Docked Widget!
I suggest you implement the two widgets (main window and the contents of the dock) in Designer and them create a dock widget in code and attach it to your main window.
Re: Help with Docked Widget!
Hi,
I use a few docked widgets in my MDI application. This is the code I wrote to do a listbox dock widget and dock it at the bottom of the main window :
Code:
m_plistWidget = new QCustomListWidget;
dockwidget->setWidget(m_plistWidget);
dockwidget->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
this->addDockWidget(Qt::BottomDockWidgetArea, dockwidget);
QCustomListWidget is a widget I did that is derived from QListWidget but has buttons as well.
Regards,
Steve
Re: Help with Docked Widget!
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:
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:
};
And this is the MainWindow.cpp
Code:
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget* parent, Qt
::WFlags fl
){
setupUi(this);
editor = new Editor(dock);
dock->setWidget(editor);
addDockWidget(Qt::RightDockWidgetArea, dock);
}
This the code of the Editor, may be will be useful.
Code:
#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:
};
Editor.cpp
Code:
#include "editor.h"
Editor
::Editor(QWidget* parent, Qt
::WFlags fl
): QWidget( parent, fl
), Ui
::Form() {
setupUi(this);
}
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!
Re: Help with Docked Widget!
You might need to call show() on the dock widget, although I'm not sure of that. I don't remember doing that with my dock widgets.
Re: Help with Docked Widget!
Thanks, I tried with that, but the dock doesn't show it.
Re: Help with Docked Widget!
Quote:
Originally Posted by
drake1983
And this is the MainWindow.cpp
Code:
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget* parent, Qt
::WFlags fl
){
setupUi(this);
editor = new Editor(dock);
dock->setWidget(editor);
addDockWidget(Qt::RightDockWidgetArea, dock);
}
I use something more like the following, and it works just fine. I even pass the dock pointer thru plugins and it works great. Mostly, I don't use "this" anywhere.
Code:
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget* parent, Qt
::WFlags fl
){
setupUi(this);
editor = new Editor();
dock->setWidget(editor);
addDockWidget(Qt::RightDockWidgetArea, dock);
}
And then the MainWindow.h looks more like :
Code:
class MainWindow
: public QMainWindow,
public Ui
::MainWindow
Note that Ui::MainWindow is public.