Plugin dock not docking

mhlabriola

New Member
Hi,

I am trying to create a dock that will dock instead of just float. From looking at the documentation, there is an API call that should do it:

QDockWidget *dock = new QDockWidget("My Dock");
QTextEdit *field = new QTextEdit();
field->setText("My Field");
dock->setWidget(field);
obs_frontend_add_dock(dock);

This creates a dock that I can open, but it only floats and won't dock. I have looked at the code for the other docks and that codes makes calls directly into UI modules instead of using the obs_frontend_add_dock API. I have seen other people get this working by copying some of the UI code into their plugin, but that code looks a lot like what's built into the obs_frontend_add_dock API call. Am I missing something simple?
 

mhlabriola

New Member
I missed adding the parent:

QDockWidget *dock = new QDockWidget("My Dock",(QWidget *)obs_frontend_get_main_window());

It window docks now, but still doesn't remember that it was docked and always opens in the upper left corner of the screen.
 

mhlabriola

New Member
Using obs_frontend_add_dock was the mistake. This works:

QMainWindow *main_window = (QMainWindow *)obs_frontend_get_main_window();
QDockWidget *dock = new QDockWidget("My Dock", main_window);
QTextEdit *field = new QTextEdit();
field->setText("My Field");
dock->setWidget(field);
main_window->addDockWidget(Qt::RightDockWidgetArea, dock);
 

mhlabriola

New Member
obs_frontend_add_dock adds the dock to the Dock menu, so it has to be called if you want your dock in the dock menu.

addDockWidget docks your dock.
 
Top