QDialog Location



  • Hi,

    I've tried to set the location of my QDialog Popup window to the bottom right of my desktop.
    @
    QDesktopWidget *desktop = new QDesktopWidget();
    int desk_width = desktop->width()-100;
    int desk_height = desktop->height() -100;

    this->move(desk_width,desk_height);
    @
    The problem is, it says my width = 5245
    and height = 1080

    I've connected 3 monitors to my pc.
    might this be the problem for the width?

    how do I solve this?

    Edit: use @ tags around code please; Andre



  • First of all, you should get your QDesktopWidget from QApplication instead of just creating an instance.

    You have setup your system to have one big desktop, so QDesktopWidget reports that (total) size. If you want to stick to the 'current' screen, you'll need to fiddle a bit with using the screen geometries also provided by QDesktopWidget. Find out what screen your your main window is on, then get the bottom right corner of that screen.

    Also note that you are moving your dialog off screen at the moment. You are now moving the top left corner of your window to the bottom right corner of the screen. Hence, the window will fall off. Substract the window height and width from the coordinates to move to instead.



  • thank you for the answer,
    this worked for me:

    @ QDesktopWidget desktop_widget;
    QRect mainScreenSize = desktop_widget.availableGeometry(desktop_widget.primaryScreen());
    int mainScreenHeight = mainScreenSize.height();
    int mainScreenWidth = mainScreenSize.width();

    int dialogWidth = this->width();
    int dialogHeight = this->height();
    
    this->move(mainScreenWidth - dialogWidth, mainScreenHeight - dialogHeight);
    

    @


Log in to reply
 

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