023.PyQt5_QWidget_信息提示

信息提示

  1. 状态栏提示
  2. 工具栏提示
  3. 这是啥提示

  • 状态栏提示
  • 需要有状态栏的窗口控件才能显示(QMainWindow)
    • QMainWindow:组合控件;包含标题栏、菜单栏、工具栏、工作区域、状态栏
    • 组合控件内部很多控件都是懒加载(不会自动加载,用户需要用的时候需要手动触发懒加载)
  • 鼠标停在控件上时, 展示在窗口底部状态栏
    setStatusTip(str)           # 设置状态栏显示的内容
    
    statusTip()                 # 获取状态栏显示内容
    
  • 工具栏提示
  • 鼠标悬停在控件上一会后, 展示在旁边
    setToolTip(str)                 # 设置工具栏显示的内容
    
    toolTip()                       # 获取工具栏显示内容
    
    setToolTipDuration(msec)        # 设置消息显示的时长(毫秒)
    
    toolTipDuration()               # 获取消息显示的时长
    
  • 这是啥提示
  • 需要将鼠标切换为带?模式(窗口设置)
    # 两种方式设置都可以
    window.setWindowFlags(Qt.Dialog)
    window.setWindowFlags(Qt.WindowContextHelpButtonHint)
    
  • 设置鼠标样式为带?的不行
  • 切换到"查看这是啥"模式, 点击该控件时显示
    setWhatsThis(str)           # 设置切换到"查看这是啥"模式, 点击该控件时显示内容
    
    whatsThis()                 # 获取切换到"查看这是啥"模式, 点击该控件时显示内容
    

  • 示例代码
    from PyQt5.Qt import *
    import sys
    
    app = QApplication(sys.argv)
    # 定义一个组合控件的窗口
    window = QMainWindow()
    # 触发底部状态栏懒加载
    window.statusBar()
    # 两种方法设置窗口标志,右上角显示问号
    window.setWindowFlags(Qt.Dialog)
    # window.setWindowFlags(Qt.WindowContextHelpButtonHint)
    
    window.resize(500, 200)
    window.setWindowTitle('消息提示')
    
    # 鼠标停在控件上时, 在底部状态栏显示一段文本
    window.setStatusTip('这是QMainWindow窗口')
    
    
    labe = QLabel(window)
    labe.setText('百度一下')
    
    # 鼠标停在控件上时, 在底部状态栏显示一段文本
    labe.setStatusTip('这是一个标签控件')
    
    # 鼠标悬停在控件上一会后, 在旁边显示一段文本
    labe.setToolTip('这是标签控件,工具栏显示')
    
    # 设置旁边展示的文本显示时长为3秒
    labe.setToolTipDuration(3000)
    
    # 设置切换到"查看这是啥"模式, 点击该控件时显示
    # 前提:需要将鼠标切换到带?模式
    labe.setWhatsThis('这是啥模式显示提示')
    
    
    
    window.show()
    sys.exit(app.exec_())
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
class MainWindow(QMainWindow): def init(self): super().init() self.setFixedSize(800, 600) main_layout = QVBoxLayout() central_widget = QWidget() central_widget.setLayout(main_layout) self.setCentralWidget(central_widget) button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.clicked.connect(self.show_query1_result) button_layout.addStretch() button_layout.addWidget(button1) button_layout.addStretch() layout = QHBoxLayout() layout.addStretch() layout.addLayout(button_layout) layout.addStretch() widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) main_layout.addLayout(button_layout) self.query1_window = QueryResultWindow() def show_query1_result(self): db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) self.query1_window.table_widget.setHorizontalHeaderLabels( ["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"]) for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) self.query1_window.show() class QueryResultWindow(QWidget): def init(self): super().init() self.setFixedSize(800, 600) self.table_widget = QTableWidget() self.table_widget.setEditTriggers(QTableWidget.NoEditTriggers) self.table_widget.setSelectionBehavior(QTableWidget.SelectRows) layout = QVBoxLayout() layout.addWidget(self.table_widget) self.setLayout(layout) if name == 'main': app = QApplication(sys.argv) loginWindow = LoginWindow() loginWindow.show() sys.exit(app.exec_()))数据展示页面怎么设置筛选器按ID筛选结果并展示的整体代码
05-24

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

失心疯_2023

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值