QWidget 实现 打破布局 或者 当前窗体内的 弹窗 (借助伪造实现)

简介:   but = QtWidgets.QToolButton(Dialog2) but.setText('**') but.setAutoRaise(True) layout.

 

 

but = QtWidgets.QToolButton(Dialog2)
    but.setText('**')
    but.setAutoRaise(True)
    layout.addWidget(but)
    Dialog2.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool)  
    Dialog2.setWindowOpacity(1)
    Dialog2.setAttribute(QtCore.Qt.WA_TranslucentBackground)

 

 

Qt.Popup     Window    Indicates that the widget is a pop-up top-level window, i.e. that it is modal, but has a window system frame appropriate for pop-up menus.

 

 

Qt.Tool        Indicates that the widget is a tool window. A tool window is often a small window with a smaller than usual title bar and decoration, typically used for collections of tool buttons. If there is a parent, the tool window will always be kept on top of it. If there isn't a parent, you may consider using Qt::WindowStaysOnTopHint as well. If the window system supports it, a tool window can be decorated with a somewhat lighter frame. It can also be combined with Qt::FramelessWindowHint. On OS X, tool windows correspond to the Floating class of windows. This means that the window lives on a level above normal windows; it impossible to put a normal window on top of it. By default, tool windows will disappear when the application is inactive. This can be controlled by the Qt::WA_MacAlwaysShowToolWindow attribute.

 

 

 

from PyQt5 import QtCore, QtGui, QtWidgets
class Popup(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(Popup, self).__init__(parent )
        self.setWindowOpacity(1)     
        
        # 必须是以顶级弹窗的形式出现,否则最小的长度不好设置
        # 最大化 和 最小化的按钮占地方
        self.setWindowFlags( QtCore.Qt.Popup | QtCore.Qt.FramelessWindowHint )
        
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.setupUi()
        
        # 只能放两个
        self._uis = []
        
    def setupUi(self):
        
        layout_main = QtWidgets.QVBoxLayout(self)
        self.setLayout(layout_main)
        layout_main.setContentsMargins(0, 0, 0, 0)
        layout_main.setSpacing(0)
        
        
        layout_top = QtWidgets.QHBoxLayout()
        layout_top_1 = QtWidgets.QHBoxLayout()
        spacerItem_1 = QtWidgets.QSpacerItem(2, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        
        self._layout_top = layout_top_1
        layout_top.addLayout(layout_top_1)
        layout_top.addItem(spacerItem_1)
        layout_top.setStretch(1, 1)
        
        
        layout_bottom = QtWidgets.QHBoxLayout()        
        layout_bottom_1 = QtWidgets.QHBoxLayout()        
        self._layout_bottom = layout_bottom_1
        
        spacerItem_2 = QtWidgets.QSpacerItem(2, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        layout_bottom.addLayout(layout_bottom_1)
        layout_bottom.addItem(spacerItem_2)
        layout_bottom.setStretch(1, 1)
        
        
        
        layout_main.addLayout(layout_top)
        layout_main.addLayout(layout_bottom)
        
    # 隐藏事件 的 重新          
    def hideEvent(self, event):
        print('hideEvent')
        
    def addShow(self, ui_1, ui_2):
        self._layout_top.addWidget(ui_1)
        self._layout_bottom.addWidget(ui_2)
        
        self._uis = [ui_1, ui_1]
       
    
def showPop(newText):
    
    
    sender = widget.sender()
    
    print('newText', newText, sender.text(), pop.width())
    
    # 需计算长度才行
    pop.resize(80, 80)
    
    pop.show()
    but_1.setFocus()
    point = input.pos()
    point_global = input.mapToGlobal(point)
    pop.move(point_global.x() -  point.x(), point_global.y() -  point.y())
    print(point_global.x(), point_global.y(), point.x(), point.y())
    
        
if __name__ == "__main__": 
    import sys
    app = QtWidgets.QApplication(sys.argv)
    
    pop = Popup()
    but_1 = QtWidgets.QLineEdit()
    but_1.setFixedSize(50, 20)
    but_1.setText('aa')
    
    but_2 = QtWidgets.QLineEdit()
    but_2.setFixedSize(80, 80)
    but_2.setText('bb')
    pop.addShow(but_1, but_2)
    print('aa')
    
    widget = QtWidgets.QWidget()
    
    layout = QtWidgets.QVBoxLayout(widget)
    
    input = QtWidgets.QLineEdit()
    layout.addWidget(input)
    
    input2 = QtWidgets.QLineEdit()
    layout.addWidget(input2)
    
    
    input.textChanged.connect(showPop)
    
    
    widget.show()
    
    sys.exit(app.exec_())

 

相关文章
|
设计模式 缓存 编译器
【C++ 元对象系统03】深入探索Qt反射:从原理到实践
【C++ 元对象系统03】深入探索Qt反射:从原理到实践
1219 5
|
监控 前端开发 JavaScript
Qt Quick调试之道:跟踪、输出与打印信息的全面攻略
Qt Quick调试之道:跟踪、输出与打印信息的全面攻略
1390 0
|
存储 运维 IDE
|
9月前
|
人工智能 自然语言处理 数据可视化
大型企业如何建设BI系统(2025年12月更新)
在数字化转型加速背景下,瓴羊Quick BI凭借智能分析、低门槛操作与灵活部署,助力大型企业构建高效BI体系。融合大模型的“智能小Q”实现自然语言交互与报告自动生成,支持多源数据集成与跨部门协同,连续五年入选Gartner魔力象限,广泛应用于高管驾驶舱、运营监控等场景,推动数据驱动决策。
|
缓存 监控 数据挖掘
唯品会item_get - 获得vip商品详情深度分析及 Python 实现
唯品会 item_get 接口用于获取商品详情,包括基础信息、价格、库存、规格、促销、店铺等数据,适用于电商比价、竞品分析、数据分析等场景。接口需通过 appkey + access_token 认证,支持字段筛选,调用时需注意频率限制与数据合规使用。
|
9月前
|
人工智能 数据可视化 安全
实时云渲染:数字孪生走向“虚实共生”的核心技术引擎
数字孪生正从可视化迈向智能体与全域协同,呈现全空间、全要素、全生命周期的体系化跃迁。2025年十大关键词涵盖低空经济、韧性城市、智能工厂等场景,实时云渲染技术突破算力瓶颈,推动数字孪生走向“可算、可管、可协同”的虚实共生未来。
实时云渲染:数字孪生走向“虚实共生”的核心技术引擎
|
机器人 API 定位技术
具身智能干货|ROS2理论与实践系列(二):ROS2通信机制核心
机器人是一种高度复杂的系统性实现,一个完整的机器人应用程序可能由若干功能模块组成,每个功能模块可能又包含若干功能点,在不同功能模块、不同功能点之间需要频繁的进行数据交互。比如以导航中的路径规划模块为例: 路径规划时就需要其他功能模块输入数据,并输出数据以被其他模块调用。 输入的数据有地图服务提供的地图数据、定位模块提供的机器人位姿数据、人机交互模块提供的目标点数据......。 输出的路径信息则被运动控制订阅或是回显在人机交互界面上。 那么这些相对独立的功能模块或功能点之间是如何实现数据交互的呢?在此,我们就需要介绍一下ROS2中的通信机制了。
3103 62
|
人工智能 API
MMedAgent:专为医疗领域设计的多模态 AI 智能体,支持医学影像处理、报告生成等多种医疗任务
MMedAgent 是专为医疗领域设计的多模态AI智能体,支持多种医疗任务,包括医学影像处理、报告生成等,性能优于现有开源方法。
1038 19
MMedAgent:专为医疗领域设计的多模态 AI 智能体,支持医学影像处理、报告生成等多种医疗任务
|
Java 关系型数据库 MySQL
ssm027学校运动会信息管理系统(文档+源码)_kaic
本文介绍了基于B/S结构的学校运动会信息管理系统开发过程。该系统采用JSP技术和MySQL数据库,确保了系统的安全性和稳定性。系统界面友好、操作简便,涵盖系统概述、分析、设计、数据库设计和测试等环节,实现了学校运动会信息管理的重要功能。经过测试,系统运行稳定,操作便捷,具备全面的功能、良好的可扩展性和维护性,有效提升了运动会信息管理的效率和准确性。关键词:学校运动会信息管理;B/S结构;JSP技术;MYSQL数据库。