很难用简短的画描述清楚,问题写在了最后 | python | python 技术论坛-大发黄金版app下载

点击我的自选按钮时,会在屏幕的左上角弹出一个很小的窗口,当点击股票名字时,重绘事件就发生在那个小窗口中,而childwindowk的k线图没有被更新,
如果在mysekect中不实例化self.childwindowk = childwindowk(self)那么paintevent函数就不会执行,如何在点击股票名字的时候可以更新,
paintevent中的绘图?

day_k(qp=qp, x1=self.x, y1=self.y, width=self.width(), height=self.height(), self=self
, leftbutton=self.leftbutton, end=self.ends, df=self.df)这个函数的绘图逻辑代码太多,我就不发了,发了也没什么用

class mainwindowa(qmainwindow):
    def __init__(self, parent=none):
        super().__init__(parent)
        self.mysekect = mysekect(self)
        self.file = open('end_val.json', 'r ', encoding=de)   # 读取 指标窗口个数
        self.data = json.load(self.file)
        self.init_ui()
    def init_ui(self):
        self.setwindowtitle("主窗口 b")
        screen = qapplication.primaryscreen().geometry()
        self.screenwidth = screen.width()
        self.screenheight = screen.height()
        self.setgeometry(0, 0, self.screenwidth, self.screenheight)
        self.mdi_area = qmdiarea()
        self.setcentralwidget(self.mdi_area)
        self.toggle_button1 = qpushbutton('我的自选', self)    # 我的自选
        self.toggle_button1.setstylesheet(self.qss_button(int(self.screenheight * 0.015)))
        self.toggle_button1.clicked.connect(self.show_stock_dialog)
        self.childwindowk = childwindowk(self.mdi_area, ends=self.data["3"])
        self.mdi_area.addsubwindow(self.childwindowk)
        self.spin_box = qspinbox(self)
        self.spin_box.setvalue(self.data["3"])  # 指标窗口个数
        self.spin_box.valuechanged.connect(self.values_button)
        self.toggle_button2 = qpushbutton('我的板块', self)
        self.toggle_button2.setstylesheet(self.qss_button(int(self.screenheight * 0.015)))
    def values_button(self, values):   # 窗口个数 槽函数
        self.childwindowk.values_button(values)
        self.file.seek(0)
        json.dump({'3': values}, self.file, ensure_ascii=false)
        self.file.truncate()
    def show_stock_dialog(self):
        visible = self.mysekect.isvisible()
        self.mysekect.setvisible(not visible)
    def qss_button(self, number):
        return f"""
        qpushbutton {{
            font-size: {number}px;
            font-weight: bold; /* 设置字体为加粗 */
            color: black;
            background-color: #00b2ee;
            border: 1px solid white; /* 设置边框颜色与背景色相同 */
            border-radius: 5px; /* 可选:设置边框圆角 */
        }}
        qpushbutton:pressed {{
            background-color: #98f5ff; /* 可选:设置按钮按下时的背景色 */
        }}
        """
    def resizeevent(self, event):
        super().resizeevent(event)
        new_size = event.size()
        self.width = new_size.width()
        self.height = new_size.height()
        button_height = int(self.height * 0.02917)
        button_width = int(self.width * 0.052)
        # upper_frame_height = int(self.height * 0.035)   # 上边框厚度
        self.toggle_button1.move(button_width * 1, 0)
        self.toggle_button1.resize(button_width, button_height)    # 我的自选
        self.spin_box.resize(button_width, button_height)    #指标
        self.toggle_button2.move(button_width * 2, 0)
        self.toggle_button2.resize(button_width, button_height)    # 我的板块
        self.childwindowk.update_size(self.width, self.height)   # k线窗口
        self.mysekect.update_size(self.width, self.height)  # 我的自选窗口
    def main_width_height(self):
        if self.width:
            return self.width, self.height
class childwindowk(qmdisubwindow):
    xy = signal(float, float)
    def __init__(self, parent=none, ends=none):
        super(childwindowk, self).__init__(parent)
        self.swift = open('swift.json', 'r', encoding=de)
        self.code = json.load(self.swift)['c']
        self.df = pd.read_csv(f'e:/tdxx/day/{self.code}.csv', encoding=de).values.tolist()
        self.setmousetracking(false)
        self.x, self.y, self.leftbutton, self.ends = 0, 0, 1, ends
        self.xy.connect(self.update_paint)
    def values_button_js(self):
        if self.ends:
            return self.ends
    def values_button(self, end):
        self.ends = end
        self.values_button_js()
        self.update()
    def mousepressevent(self, event: qmouseevent):
        if event.button() == qt.leftbutton:    # 左键
            self.leftbutton  = 1
            if self.leftbutton % 2 == 0:
                self.setmousetracking(true)
                self.left_button()
                self.update()
            else:
                self.setmousetracking(false)
                self.left_button()
                self.update()
        elif event.button() == qt.rightbutton:    #右键
            print("鼠标右键被点击")
        else:
            super().mousepressevent(event)
    def left_button(self):
        if self.leftbutton:
            return self.leftbutton
    def mousemoveevent(self, event):
        self.x = event.position().x()
        self.y = event.position().y()
        self.xy.emit(self.x, self.y)
        self.update()  # 触发重绘
    def update_paint(self, x, y):
        pass
    def paintevent(self, event):
        print(self.code, 'pai')
        print(self.df[-1], 'pai')
        print(self.ends, 'pai')
        qp = qpainter(self)
        day_k(qp=qp, x1=self.x, y1=self.y, width=self.width(), height=self.height(), self=self
              , leftbutton=self.leftbutton, end=self.ends, df=self.df)
    def update_size(self, new_width, new_height):   # 主窗口发送来的
        y1 = int(new_height * 0.031)
        y2 = int(new_height * 0.969)
        self.setgeometry(0, y1, new_width, y2)
        self.update()
    def js_mysekect(self, *a):   # mysekect 发送来的
        self.code = a[0][0:8]  '.csv'
        self.df = pd.read_csv(f'e:/tdxx/day/{self.code}', encoding=de).values.tolist()
        self.ends = a[1]
        self.assign_code()
        self.update()
    def assign_code(self):
        if self.code and self.df:
            return self.df
class mysekect(qdialog):   # 我的自选弹出窗口
    def __init__(self, parent=none):
        super(mysekect, self).__init__(parent)
        self.childwindowk = childwindowk(self)
        num = open('end_val.json', 'r ', encoding=de)   # 读取 指标窗口个数
        self.n = json.load(num)['3']
        self.setwindowflags(qt.tool | qt.framelesswindowhint)  # 设置无边框窗口
        self.setvisible(false)   #设置默认状态为关闭
        self.width, self.height, self.code = none, none, none
        self.initui()
    def initui(self):
        layout = qvboxlayout()
        self.list_widget = qlistwidget()
        self.list_widget.additems(["sh600000 浦发银行    ff", "股票b", "股票c", "股票d", 'c', 'b', 'a'])  # 添加股票项
        self.list_widget.itemclicked.connect(self.update_swift)
        layout.addwidget(self.list_widget)   # 添加到布局管理器
        self.setlayout(layout)    # 将布局设置为当前部件的布局
    def update_size(self, new_width, new_height):    # 主窗口发送来的
        self.setgeometry(0, int(new_height * 0.068), int(new_width * 0.2), int(new_height * 0.947))
        self.width, self.height, = new_width, new_height
        self.width_height()
        # self.setgeometry(0, int(new_height * 0.07), int(new_width * 0.2),
        #                  int(new_height - new_height * 0.07))   #有边框的弹出窗口
    def update_swift(self, code):
        self.code = code.text()
        self.swift()
        self.width_height_swift()
    def width_height(self):
        if self.width and self.height:
            return self.width, self.height
    def swift(self):
        if self.code:
            return self.code
    def width_height_swift(self):
        width, height = self.width_height()
        code = self.swift()[0:8]
        nn = self.n
        if width and height and code:
            # self.childwindowk = childwindowk()
            self.childwindowk.js_mysekect(code, nn)
        else:
            print('a')
if __name__ == '__main__':
    app = qapplication(sys.argv)
    main_window_a = mainwindowa()
    main_window_a.show()
    sys.exit(app.exec())
讨论数量: 4
jason990420

using code block for your script, or bad code will be shown as above.

```python

your code

```

5天前
rxts (楼主) 4天前
jason990420 (作者) 4天前
rxts (楼主) 1天前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
网站地图