Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Opening a dialogue next to main window



  • I am opening a Dialogue to the left of the main window. There is plenty of room and I know how to fix it if there isn't (using a max function) - this is just the bare bones of the problem:

    myDlg->show();
    int xx = x() - myDlg->frameGeometry().width();
    myDlg->move(xx, y());
    

    According to the documentation this ought to cause the right hand edge of the dialogue to be up against the left hand edge of the main window. It isn't! There's a (approx) 15 pixel gap! Is this caused by Win10's 'shadow' nonsense - which I have turned off - or something else? Help would be appreciated.


  • Moderators

    @BrianE
    use geometry().x()



  • I can't! I get an error message:

    D:\Qt Projects\xxx.cpp:280: error: '((MainWindow*)this)->QWidget::geometry' does not have class type
         int xx = geometry.x() - myDlg->frameGeometry().width();
                  ^

  • Lifetime Qt Champion

    @BrianE said in Opening a dialogue next to main window:

    ((MainWindow*)this)->QWidget::geometry

    That looks odd
    are you casting this ?

    All widgets have geometry()
    http://doc.qt.io/qt-5/qwidget.html#geometry-prop


  • Moderators

    @BrianE

    
    myDlg->show();
    int xx = mainWin->geometry().right();
    myDlg->move(xx, y());
    


  • The only thing that has worked so far is this:

        myDlg->show();
        int xx = MainWindow::geometry().x() - myDlg->frameGeometry().width();
        myDlg->move(xx, y());
    

    However, there is still a six or seven pixel gap between RH edge of myDlg and LH edge of MainWindow.

    More:

    int xx = MainWindow::geometry().x() - myDlg->geometry().width();
    

    gives you an big overlap! and

    int xx = MainWindow::frameGeometry().x() - myDlg->geometry().width();
    

    gives me as close to what I want as we're going to get ie one/two pixel overlap which is understandable.

    This does solve the problem, so thanks for the input, but is absolutely not what I was expecting from the documentation. Mind you, how anything works in Win10 is nothing short of miraculous anyway.


  • Moderators

    @BrianE
    oh i thought the whole time you want to display it outside next to the mainwindow.
    See this



  • ????? That's exactly what I wanted to do! The top left corner of myDlg to be myDlg's width to the left of MainWindow's top left. Basically that means Dlg.TL = Main.TL - Dlg.W and my original code used the documented parts of the window as required. It was using the 'correct' parts that gave the gap between Dlg.R and Main.L and I still don't know why!


Log in to reply