主管给了一个任务,让在不同的分辨率使用不同的ui。搜索了网上的用法,还是没有解决问题。试了半天,
current_monitor = desktop.screenNumber(self)
rect = desktop.screenGeometry(current_monitor)
上述代码始终返回主屏幕的分辨率。后来无意中发现,show之后,获取的分辨率是正常的,于是重写了showEvent就解决了
这里有个限制,必须有一个主layout,否则无效!
这里有个限制,必须有一个主layout,否则无效!
这里有个限制,必须有一个主layout,否则无效!
class LaucherWidget(QtWidgets.QWidget):
def __init__(self, parent):
super().__init__(parent=parent)
def showEvent(self, event):
desktop = QDesktopWidget()
current_monitor = desktop.screenNumber(self)
rect = desktop.screenGeometry(current_monitor)
self.ui = Ui_launcher.Ui_launcher()
if rect.width() == 1366:
self.ui = UI_launcher1366_768.Ui_launcher()
self.ui.setupUi(self)
对qt不是很熟悉,勉强能用的程度。高手忽略
(pyqt5实现的)
温馨提示:代码仅供参考
补充:
建了一个qq群:389954854,主要目的是互帮互助,通过交流促进python技术。很多初学者往往不知道如何下手,还等什么,快快加入进来吧!
或者关注微信公众号:python码码有趣的