我有几个关于python qpainter pyqt5的问题

问题描述

我有几个关于python的问题 在我将在下面添加代码中,我想在 qlabel 中使用 qpainter 进行绘制,并且希望在单击按钮时发生这种情况。但无论如何我都无法将其分配给按钮。当表单打开时,代码直接工作。怎么改,只有在点击按钮时才运行。另外,当我点击这个按钮时,我会进行计算,然后制作这张图。

enter image description here

from PyQt5 import QtGui
from math import *
from Dere_Kesit_Hesabi_python import Ui_MainWindow
import os
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class dere_example(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)
        self.setFixedSize(self.size())
        n=0
        h=0
        b=0
        Q100=0
        Q500=0
        J=0
        m=0

        user = os.environ['USERNAME']
        self.setwindowTitle("Dere Kesit Hesabı-" + user)

       
        self.ui.btnhesap.clicked.connect(self.hesapkitap)
        self.ui.btnhesap.clicked.connect(self.paintEvent)
      

    def paintEvent(self,e):
        pixmap = Qpixmap(self.ui.lblciz.size())
        pixmap.fill(Qt.transparent)
        painter = QPainter(pixmap)
        painter.setPen(QPen(Qt.blue,2,Qt.solidLine))
        x = 100
        y = 100
        h=3
        b=4
        painter.drawLine(x,y,x + h,y - h)
        painter.drawLine(x + h,y - h,x + b + h,y - h)
        painter.drawLine(x + b + h,x + b + 2 * h,y)

        self.ui.lblciz.setpixmap(pixmap)
        painter.end()

    

    def hesapkitap(self):

        global n
        global h
        global b
        global Q100
        global Q500
        global J
        global m

        try:
            n = float(self.ui.txtn.text().replace(",","."))
            Q500 = float(self.ui.txtq500.text().replace(","."))
            Q100 = float(self.ui.txtq100.text().replace(","."))
            j = float(self.ui.txtj.text().replace(","."))
            h = float(self.ui.txth.text().replace(","."))
            b = float(self.ui.txtb.text().replace(","."))
            byan = sqrt(h * h + h * h)
            büst = 2 * h + b
            A = round(((büst + b) / 2 * h),4)
            Ç = round((b + 2 * byan),4)
            R = round((A / Ç),4)
            V = round((1 / n * pow(R,(2 / 3)) * pow(j,(1 / 2))),4)
            Q = round((A * V),2)

            self.ui.lblAlan.setText(str(A) + " m2")
            self.ui.lblcevre.setText(str(Ç) + " m")
            self.ui.lblyaricap.setText(str(R))
            self.ui.lblhiz.setText(str(V) + " s")
            self.ui.lblmaxdebi.setText(str(Q) + " m3/s")
            h500 =round(( Q500 * h / Q),2)
            h1000 = round((Q100 * h / Q),2)

            if (Q500 <= Q):
                self.ui.lblQ500sonuc.setText("Q500 : "+str(Q500)+" < "+"Q : "+str(Q)+" olduğundan kesit gelen Q500 debisi için  yeterli!")
                self.ui.lblQ500sonuc.setStyleSheet("color:rgb(0,150,0)")
            else:
                self.ui.lblQ500sonuc.setText("Q500 : "+str(Q500)+" > "+"Q : "+str(Q)+" olduğundan kesit gelen Q500 debisi için  yetersiz!")
                self.ui.lblQ500sonuc.setStyleSheet("color:rgb(255,0)")

            if (Q100 <= Q):
                self.ui.lblQ100sonuc.setText("Q100 : "+str(Q100)+" < "+"Q : "+str(Q)+" olduğundan  kesit gelen Q100 debisi için  yeterli!")
                self.ui.lblQ100sonuc.setStyleSheet("color:rgb(0,0)")
            else:
                self.ui.lblQ100sonuc.setText("Q100 : "+str(Q100)+" > "+"Q : "+str(Q)+" olduğundan kesit gelen Q100 debisi için  yetersiz!")
                self.ui.lblQ100sonuc.setStyleSheet("color:rgb(255,0)")
        except:
            self.ui.statusbar.showMessage("Lütfen bilgileri eksiksiz doldurunuz!",3000)
            self.ui.statusbar.setStyleSheet("color:rgb(255,0)")

    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)