how to keep a floating window above/ or center of QMainWindow
-
I have following code
d_subView = new IN_CURRENT_POOL GQSubView(this);
if (corner == Qt::NoDockWidgetArea) {
setCentralWidget(d_errorView);
} else {
QDockWidget* w = addDockWidget(d_errorView, tr("E&rror"), true, corner);
w->setFloating(true);
w->close();
}where GQSubView is derived from QWiddget and this is derived window .. Now when open the sub window it is in floating state which is correct but it gets placed at top left corner of the screen . How to keep it to the center of QMainwindowor at least at the top of QMainWindow
-
I tried the following thing but still it is not working
if(parent) {
move(parent->geometry().center());
}
QHBoxLay -
No I do not want to block the access the window should come as floating and then if the user wants he should able to dock and do other activities
-
hi
its not really clear what u have and what you try,. but it sounds to me
you are trying to start off with a DockWidget in floating mode.If I make a default project and use the following code.
the app starts up with a floating dock in center of mainwindow.Is this what you are trying?
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QDockWidget *dockWidget = new QDockWidget(tr("Dock Widget"), this); addDockWidget(Qt::TopDockWidgetArea, dockWidget ); dockWidget -> setFloating(true); }
So if your project really do differnt and place a dock in screen corner then
please run sample so we know if there is something else going on.
https://www.dropbox.com/s/uset21c2zf897pr/floatfromstart.zip?dl=0also , your ELSE seems funky
...
else {
QDockWidget* w = addDockWidget(d_errorView, tr("E&rror"), true, corner);
w->setFloating(true);
w->close(); <<< here u close it ????
}Why do u close the DockWidget?
-
To Clarify more
First When I create the Main window I create the Dockwidget , setFloating as true and then close it . When I want click the menuActionmyActionForMenu , the I should open the window . but it is not happeningI have a MainWindow
class MyMainWindow : public QMainWindow {
MyQActions* actions() {return d_actions;}
MyView* myView() {return d_myView;}
createErrorWidget(Qt::DockWidgetArea corner);
createMenuandToolBars();
}
void MyMainWindow::createMyWidget(Qt::DockWidgetArea corner)
{
/*d_myView = new IN_CURRENT_POOL GQMyView(this);if (corner == Qt::NoDockWidgetArea) {
setCentralWidget(d_errorView);
} else {
QDockWidget* w = addDockWidget(d_errorView, tr("E&rror"), true, corner);
w->setFloating(true);
w->close();
}
}
void MyMainWindow::createMenuAndToolBars()
{
// tool & menu bar
d_actions = new IN_CURRENT_POOL MyQActions(this);
}MyActions::MyActions(MyMainWindow* w) {
d_actionMyAction = act = new IN_CURRENT_POOL QAction(tr("My &Action"), this);
act->setStatusTip(tr("Check Placement"));
connect(act, SIGNAL(triggered()), this, SLOT(myActionForMenu()));}
void MyActions::myActionForMenu()
if(d_parent->myView()) {
d_parent->myView()->show();
}}
-
@Qt-Enthusiast said:
QDockWidget* w = addDockWidget(d_errorView, tr("E&rror"), true, corner);
w->setFloating(true);
w->close();here the QDockWidget is w. locally defined.
and later u say
d_parent->myView()->show();is that myView() returning a dock?
I would expect you to talk to w again..