python - PyQT5 on mac: determine the screen containing the QMainWindow -




i using mac multidisplay environment, monitors @ different resolutions , want able determine dpi settings of window "holding" qmainwindow, in order set proper scaling matplotlib figures. in real application implement control when window moved, redraw operation detect different dpi settings , show consistent output, right struggling detection.

i understood qdesktopwidget class should report screennumber in qwidget open. in appkit can use methods access resolution.

however, in following example code reports window open in screen 0 (the main laptop screen), when it's inside external monitor.

am missing trivial? in pyqt learning stage, there more obvious ways deal problem, should common enough?

from pyqt5.qtwidgets import * pyqt5.qtgui import *    pyqt5.qtcore import * import sys import appkit  class formwidget(qwidget):     def __init__(self,parent):         super(formwidget,self).__init__(parent)         self.parent=parent          self.lblinfo = qlabel(' ',self)         self.lblresolution= qlabel(' ',self)          d=qdesktopwidget()         iscreen=d.screennumber(self)         self.lblinfo.settext('this widget in screen {0}'.format(iscreen))          screeninfo=[screen.devicedescription() screen in appkit.nsscreen.screens()]          width=screeninfo[iscreen]["nsdevicesize"].sizevalue().width         height=screeninfo[iscreen]["nsdevicesize"].sizevalue().height         dpi=screeninfo[iscreen]["nsdeviceresolution"].sizevalue().width          self.lblresolution.settext('{0:.0f}x{1:.0f} @ {2:.0f} dpi'.format(width,height,dpi))         layout=qvboxlayout()         layout.addstretch(1)         layout.addwidget(self.lblinfo)         layout.addstretch(1)         layout.addwidget(self.lblresolution)         layout.addstretch(1)          self.setlayout(layout)  class mywidget(qmainwindow):      def __init__(self, parent = none):         super(mywidget,self).__init__(parent)         self.form_widget=formwidget(self)         self.form_widget.layout=qvboxlayout(self.form_widget)         self.form_widget.layout.addwidget(self.form_widget)         self.setcentralwidget(self.form_widget)         self.initializegui()      def initializegui(self):         #add menu, statusbar, etc. on qmainwindow         self.resize(500,400)         self.show()   if __name__ == '__main__':      app = qapplication(sys.argv)     w=mywidget()     sys.exit(app.exec_()) 





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -