python - PyQt5 Weird window position issue -
the codes above, weirdly have issue. don't understand why if set y
size of window more 923
, window not placed @ middle of screen. goes top-left corner of screen.
from pyqt5.qtwidgets import qapplication,qdesktopwidget,qmainwindow pyqt5 import qtcore import sys class cssden(qmainwindow): def __init__(self): super().__init__() self.mwidget = qmainwindow(self) self.setwindowflags(qtcore.qt.framelesswindowhint) #size self.setfixedsize(1100,923) # <--- set 924 , more self.center # <-- function set window middle of screen self.show() def center(self): # <-- center function qr = self.framegeometry() cp = qdesktopwidget().availablegeometry().center() qr.movecenter(cp) self.move(qr.topleft()) app = qapplication(sys.argv) app.setstylesheet("qmainwindow{background-color: rgb(30,30,30);border: 1px solid black}") ex = cssden() sys.exit(app.exec_())
why? resolution of screen 1920x1080? don't understand why number 923
, how fix this.
edit: turns out pyqt center window automatically, after 923
why it's going left-top corner of screen? there default numbers each resolutions?
try solution answer: pyqt4 center window on active screen
def center(self): framegm = self.framegeometry() screen = qtgui.qapplication.desktop().screennumber(qtgui.qapplication.desktop().cursor().pos()) centerpoint = qtgui.qapplication.desktop().screengeometry(screen).center() framegm.movecenter(centerpoint) self.move(framegm.topleft())
this function based on mouse point located. uses screennumber function determine screen mouse current active on. finds screengeometry of monitor , center point of screen. using method, should able place window in center of screen if monitor resolutions different.
Comments
Post a Comment