pyqt5Automatic 借用一些框架,仅用少量的代码就实现了,qt5中的控件尺寸的自适应,不需要麻烦的调整水平或者垂直布局。
2.给按钮添加图片参考
给背景label和 9个按钮button 均继承自适应窗口类,使用信号连接label的高斯滤波函数
self.all_buttons = []
for i in range(9):
temp_btn = eval('self.pushButton_{}'.format(i + 1), {'self': self}) # 从 1--9
pub_button = Public_Object(main_w=self.width(), main_h=self.height(),
w=temp_btn.width(), h=temp_btn.height())
temp_btn = Automatic_Change_button(button=temp_btn, pub=pub_button)
self.all_buttons.append(temp_btn)
image_path = r"Qbutton/re_data/img.png" # 这个路径从Qbutton开始
newlabel = self.label
pub_label = Public_Object(main_w=self.width(), main_h=self.height(), w=newlabel.width(),
h=newlabel.height())
pub_label.imagePath = image_path
self.gauss_label = Automatic_change_Label(label=newlabel, pub=pub_label)
self.gauss_label.sig.connect(self.gauss_sig_fun) # 高斯滤波信号
self.gauss_label.emission_signal()
记得调用resizeEvent事件实时刷新窗口事件
super().resizeEvent(e)
self.gauss_label.label_change(self)
for btn in self.all_buttons:
btn.button.setToolTip('不要点我否则我就🥰(*╯3╰)')
btn.button_change(self)
下图实现高斯模糊
使用如下代码可以去除边框,按esc退出
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint | Qt.Tool) # 窗口置顶,无边框,在任务栏不显示图标
下面是一个自适应滑块
其他由QtWidgets继承的类均可以用Antomatic_QtWidgets.py这个函数来继承,如下案例
QtWidget1 = self.graphicsView
pub = Public_Object(main_w=self.width(), main_h=self.width(),
w=QtWidget1.width(), h=QtWidget1.height())
self.mygraphicsView = Automatic_Change_QtWidget(QtWidget1, pub)
下图是实现了界面切换,有bug(子窗口会置顶)占时还没解决。
是一个多线程交互的实例