本文主要用于自我整理和总结,便于后续参考。如果对你有帮助,提前展示一下这次实现的具体功能也是一种乐趣。具体步骤如下:在设计界面中设计的弹出窗口的大小和宽度,高度为弹出窗口的标题。想写什么就写什么,可以放在右上方。
PS:本文主要用于自我整理和总结,方便后续参考。如果只是帮到你,展示一下这次实现的具体功能也是一件开心的事情。具体程序如下:
从PyQt5导入QtWidgets,从PyQt5导入qtcore。QtCore导入Qt,QRectfrom PyQt5。QtWidgets导入QMainWindow,QApplication,QPushButton,QWidget,qtablewidgetitemtemfromuntitled导入UI _ mainwindow #导入设计界面#设计的弹出类small window(q widget):def _ _ init _ _(self):super(small window,Self)。_ _ init _ _ () self。resize (100,100) # Size (width,High) self.setWindowTitle("我是弹出的")#窗体的标题Self . setwindowflags(Qt . windowtitlehint)#显示窗口的标题栏(这样你想要什么,可以去掉右上角的按钮)Self . push button = q push button(Self)#定义一个按钮控件Self . push button . set geometry(qrect(30,30,40,40)) #参数含义:(横坐标[即距左_ _ init _ _ () self.setupui (self) #初始化窗口self . push button . clicked . Connect(self . open window)#将单击控件的动作与跳出弹出窗口的功能连接起来。self . checkbox _ 1 . state changed . connect(self . Check _ 1)#检查动作和函数之间的联系self . checkbox _ 2 . state changed . connect(self . Check _ 2)self . checkbox _ 3 . state changed . connect(self . Check _ 3)。Self.tablelist = [] #存储检查的数据#弹出函数defopenwindow(self):self . small window _ ui = small window()self . small window _ ui . show()self . small window _ ui . push button . clicked . connect(self . small window _ ui . close)#点击按钮关闭窗口#勾选函数def check_1(self,State): if state == Qt。选中:#如果选中,self . table list . append(" one ")self . table()# Update table else:self . table list . remove(" one ")self . table()def check _ 2(self,State):If State = = Qt . checked:self . table list . append(" two ")self . table()。else:self . table list . remove(" two ")self . table()def check _ 3(self,State):if State = = Qt . checked:self . table list . append(" three ")self . table()。else:self . table list . remove(" three ")self . table()#函数函数def table (self): self。tablewidget。clearcontents () # clearcontents清除除标题以外的所有内容;清除,清空表格中的所有内容,包括表头self。table widget . set rowcount(len(self。tablelist)) #自行设置行数。tablewidget .根据检查到的数字设置列计数(1) #。设置列数self . table widget . sethorizontalheaderlabels([" checked number "])#为self.tablelist中的内容设置表头num = 0:#将tablelist中的元素依次写入表中。table _ content = qtableWidgetItem(content)#转换字符串类型变量。QTableWidgetItem对象本身。TableWidget。SetItem (num,0,table _ content) # list生成填充内容,参数含义(行数,列数,内容)num+= 1 if _ _ name _ _ = = " _ _ main _ _ ":app = QA application(sys . argv)ui = main window()ui . show()sys . exit(app . exec _())
评论前必须登录!
注册