You can do something like this:
QPoint tray_center = mTrayIcon->geometry().center(); QRect screen_rect = qApp->screenAt(tray_center)->geometry(); QPoint screen_center = screen_rect.center(); Qt::Corner corner = Qt::TopLeftCorner; if (tray_center.x() > screen_center.x() && tray_center.y() <= screen_center.y()) corner = Qt::TopRightCorner; else if (tray_center.x() > screen_center.x() && tray_center.y() > screen_center.y()) corner = Qt::BottomRightCorner; else if (tray_center.x() <= screen_center.x() && tray_center.y() > screen_center.y()) corner = Qt::BottomLeftCorner;So yeah, screenAt will give you the screen you're on and corner will tell you which corner of the screen are you in.
Then you can use qApp->screenAt(tray_center)->availableGeometry() to determine the workable area of that screen and use the corner information to place your widget. You don't need to know if it's a primary , left or right screen. The available geometry is enough for your purpose.