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_())

QWidget 实现 打破布局 或者 当前窗体内的 弹窗 (借助伪造实现)的更多相关文章

  1. Delphi实现窗体内嵌其他应用程序窗体

    实现原理是启动一个应用程序,通过ProcessID得到窗体句柄,然后对其设定父窗体句柄为本程序某控件句柄(本例是窗体内一个Panel的句柄),这样就达成了内嵌的效果. 本文实现的是内嵌一个记事本程序, ...

  2. [代码]Delphi实现窗体内嵌其他应用程序窗体

    实现原理是启动一个应用程序,通过ProcessID得到窗体句柄,然后对其设定父窗体句柄为本程序某控件句柄(本例是窗体内一个Panel的句柄),这样就达成了内嵌的效果. 本文实现的是内嵌一个记事本程序, ...

  3. 创建可按比例调整的布局的 Windows 窗体

    能够正确调整大小的窗体可以提高您的用户界面的易用性. 此演练演示了如何创建当用户调整窗体大小时按比例调整的布局. 您将使用 TableLayoutPanel 控件实现一个接收联系人信息的数据输入窗体. ...

  4. Qt窗体内控件自适应调整大小

    http://stackoverflow.com/questions/3492739/auto-expanding-layout-with-qt-designer After creating you ...

  5. C# 鼠标移动Winform窗体内或者panel容器内的控件 显示虚线/实现虚线框来确定位置

    C# 鼠标移动WinForm窗体或者panel容器内的控件 移动虚线/实现虚线框来确定位置 1.用到的方法介绍 今天,根据领导指示指导移动容器内的控件,生成虚线框,使用 ControlPaint.Dr ...

  6. VS中 Winform查看窗体内控件之间的相互关系

    视图----其他窗口----文档大纲 这样可以查看之前的窗体布局关系

  7. pywin32 获取 windows 的窗体内文本框的内容

    用 spy++去确认找到了文本框的句柄了. 用函数 win32gui.SendMessage 获取不了文本框的文本内容,用 str 类型的参数接收获取的内容的话没有获取到东西,而用 PyBuffer ...

  8. C# 窗体内有子控件时鼠标检测

    public partial class FormPop : Form { public FormPop() { InitializeComponent(); } private void FormP ...

  9. 在iframe窗体内 获取父级的元素;;在父窗口中获取iframe中的元素

    在iframe中获取父窗口的元素 $(‘#父窗口中的元素ID’, parent.document).click(); 在父窗口中获取iframe中的元素 $(“#iframe的ID”).content ...

随机推荐

  1. okhttp3的使用

    http://www.qingpingshan.com/rjbc/az/110232.html 请求队列,post? 待定 http://www.07net01.com/2015/12/1017279 ...

  2. HttpServletResponse

    Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象.request和response对象即然代表请求和响应,那我们要 ...

  3. JVM调优-Java垃圾回收之分代回收

    为什么要进行分代回收? JVM使用分代回收测试,是因为:不同的对象,生命周期是不一样的.因此不同生命周期的对象采用不同的收集方式. 可以提高垃圾回收的效率. Java程序运行过程中,会产生大量的对象, ...

  4. 多重背包问题:POJ2392

    这是一道完全背包问题,只不过增加了限制条件. 在更新最大值的时候,我注释掉了错误的方式,却不明白为什么是错误的,如果有人看到这篇博客,并且知道为什么那样更新是错误的,请指教,谢谢. 上代码: #inc ...

  5. js判断访问终端

    //判断访问终端 var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; ...

  6. markdown编辑器实现笔记

    1.js代码放在head和body的区别 <html> <head> <script src="https://cdnjs.cloudflare.com/aja ...

  7. Daily Scrum 12.3

    今日完成任务: 与安卓组进行商量对数据库修改的方案.现在在等他们最终确认,确认之后进行整理以及源代码的调试. 对资源功能的代码进行阅读. 遇到困难: 关于整合,爬虫组爬到的内容和网站定位有所不符,所以 ...

  8. VB6.0 获取Excel文件工作表Sheet的名称

    获取Excel文件工作表Sheet的名称 '产生Excel文档 Dim xlapp, xlbook As Object Dim sSheetName As String Set xlapp = Cre ...

  9. Hibernate缓存之初探

    数据层的访问效率优化可能第一想到的就是利用缓存,缓存的机能可以简单理解为将从数据库中访问的数据放在内存中,在以后再次使用到这些数据时可以直接从内存中读取而不必要再次访问数据库,尽量减少和数据库的交互提 ...

  10. CoreLocation框架的使用---地理编码

    #import "ViewController.h" #import <CoreLocation/CoreLocation.h> @interface ViewCont ...