from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys





_QSS="""
QWidget {
    background-color: rgb(245, 180, 245);
}
QLabel {
    font-family: "Microsoft YaHei";
    font-size: 16px;
    color: #BDC8E2;
    background-color: #2E3648;
    padding-left: 5px;
}
QLabel:hover{
	color: #CDD8F2;
    background-color: #4E5668;
}
"""


class floatBox(QWidget):
    def __init__(self,parent:QWidget=None,items:list=None,x:int=0,y:int=0):
        QWidget.__init__(self,parent)
        self.setMouseTracking(True)
        self.setWindowFlags(Qt.WindowType.FramelessWindowHint|Qt.WindowType.NoDropShadowWindowHint|Qt.WindowType.Popup)
        self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
        self.setStyleSheet (_QSS)
        x_size,y_size=self._add_items(items)
        desk=QApplication.desktop()
        if(y+y_size>desk.height()):
            y=desk.height()-y_size
        if(x+x_size>desk.width()):
            x=desk.width()-x_size
        self.setGeometry(QRect(x, y, x_size, y_size))
    def _add_items(self,items:list):
        x_size=500
        if(items is None):
            items=["没有要显示的提示"]
        for i in range(len(items)):
            lable=QLabel(self)
            lable.setText(items[i])
            lable.setGeometry(QRect(5,5+i*25,x_size,25))
        return x_size+10,len(items)*25+10



if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = QWidget()
    widget.resize(870, 410)
    widget.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
    label=floatBox(items=["aaaaaa","bbbbbbbb","cccccccc"])
    widget.destroyed.connect(label.close)
    widget.show()
    label.show()
    a=app.exec()


