Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to keep a floating window above/ or center of QMainWindow

how to keep a floating window above/ or center of QMainWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 3.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on 12 Mar 2016, 08:52 last edited by
    #1

    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

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      Qt Enthusiast
      wrote on 12 Mar 2016, 10:17 last edited by
      #2

      I tried the following thing but still it is not working

      if(parent) {
      move(parent->geometry().center());
      }
      QHBoxLay

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 12 Mar 2016, 22:17 last edited by
        #3

        Hi,

        Do you want it to block access to your main window ? If so you should use QDialog as a base class.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on 13 Mar 2016, 05:06 last edited by
          #4

          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

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 13 Mar 2016, 08:05 last edited by mrjj
            #5

            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=0

            also , 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?

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              Qt Enthusiast
              wrote on 13 Mar 2016, 08:51 last edited by
              #6

              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 happening

              I 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();
              }

              }

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 13 Mar 2016, 08:56 last edited by mrjj
                #7

                @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..

                1 Reply Last reply
                0

                3/7

                12 Mar 2016, 22:17

                • Login

                • Login or register to search.
                3 out of 7
                • First post
                  3/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved