Managing multiple application windows on multiple monitors



  • I have an application that can launch several windows upon clicking.

    In a dual monitor system, if I drag over the main application window to a second screen in extended mode, and then launch a child window, it(the child ) always comes in the main monitor.

    How can I force the child window to always appear in the same screen/ monitor as its parent?

    The applciation is in Qt and C++.

    I have an idea to use primaryScreen and setScreen, something of the sort, but are they available for use on WIndows? And can they be used with GraphicsItem?
    If indeed possible, could someone please tell me how to use them?

    Kindly help. Thank you.



  • Hi,

    have a look at the screenGeometry method of QDesktopWidget. It will give you information about the available screens, and their individual geometry. You can move() a widget to a position inside the screen it is supposed to show on (topLeft() works). You need to know the integer Id of the target screen, or you can call it with the widget pointer of the window that is already showing on the target screen.

    If the child has no parent, it will show up on the primary screen unless told otherwise.



  • Thank you very much. I'll try it out.

    Is there any way to manage the screens without using QDesktopWidget?

    It causes several ambiguity problems in my code.



  • No, that is what that class is for. How do you mean that it causes ambiguity?



  • It's an issue which I'm having with this line..

    @connect(this, SIGNAL(setNodeitemAlive(bool)), criteria, SLOT(update(bool)));@

    this--------Object of a class type inheriting from QObject
    criteria----Object of a class type inheriting from QObject,QStandardItem and as I want, QDesktopWidget.

    Error:-ambiguous access of 'connect'
    Error 2:-argument : ambiguous conversions from 'Transition *const ' to 'const QObject *
    Error 3 'connect': identifier not found

    These are probably novice errors, but I'm new to all this.
    Thanks a lot for helping me.



  • QDesktopWidget is not meant to be subclassed. Use QApplication::desktop() to retrieve an instance and the information you need.

    QObject in general does not support multiple inheritance.



  • Yeah, you should generally try to inherit only if you need to, and otherwise just use or compose the classes that exist. What I forgot to mention is that you retrieve the desktop widget from QApplication, instead of instantiating it directly.



  • Once I get the QDesktopwidget thingy, can I exploit PrimaryScreen property?
    The PrimaryScreen is supposed to return an integer value of the screen which is in use by the parent window at the time.

    Once i move the parent window over to the other screen, and then launch a child window from there, is there a way to force the child window to use the same screen using the parentScreen() property? Something like Setscreen(parentscreen())?



  • The widget I'm referring to, now does not have a parent. I've removed that part.

    I can get the screenID of the target screen where I want the window to launch based on the position of the cursor in that screen.

    Once I have this, how do I force the window to launch in that screen?



  • What I did in a similar program is to get the screen number of the main window using the screenNumber(QWidget*) method. Then I move the new window to a coordinate on the target screen before showing.



  • Thanks a lot for your help everyone.
    I finally got it working fine.

    Much obliged, I'm sure.


Log in to reply
 

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