Help on QDialog Position



  • when i press the Parent Window's PushButton
    i want to show the child dialog window exactly below my pushButton of the Parent Dialog Window,
    May i know how to set the position of the Child dialog to fit below the pushButton , even when the Parent dialog is Maximed or Restored.
    @
    Parent Dialog

    | ---------- |
    | |pushBtn | |
    | ---------- |
    | |
    | |
    | |
    | |

    @



  • What about getting PushButton's @pos()@ value (QPoint), then setting the new window's position appropriately, like @QWidget::move (QPoint.x, QPoint.y);@ ??

    --



  • If the new window is a top level window, you have to use global coordinates.
    that means:

    @
    CMyDialog dlg;
    dlg.show();

    QPoint ptGlobal = ui->pushButton->mapToGlobal(QPoint(0, ui->pushButton->height()));
    QPoint ptLeftTop = mapToGlobal(QPoint(0,0));
    QPoint ptFrame = frameGeometry().topLeft();
    ptGlobal += (ptLeftTop - ptFrame); // add border size
    dlg.setGeometry(QRect(ptGlobal, dlg.size()));
    
    dlg.exec();
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.