2017-12-03 35 views
0

좌표가있는 텍스트를 배치하려고하지만 인수를 소개하는 방법을 모르겠습니다. 그물에서 검색 한 내용은 Qt.Allign ----이있는 예제 만 있고 설명서에 인수를 넣으면 오류가 있습니다. 그것은 파이썬에서 PyQt5와 3.6drawText()로 좌표가있는 텍스트 배치

import sys 
from PyQt5.QtCore import QTimer, Qt, QRectF 
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QVBoxLayout, QHBoxLayout 
from PyQt5.QtGui import QColor, QFont, QPainter 


class Window(QWidget): 

    def __init__(self): 
     super().__init__() 
     self.stopwatch() 

    def stopwatch(self): 

     hbox = QHBoxLayout() 

     self.setLayout(hbox) 
     self.setWindowTitle("Example") 
     self.setGeometry(400,400,400,200) 

     self.formato = "0:00.0" 

     self.show() 


    def paintEvent(self, event): 
     qp = QPainter() 
     qp.begin(self) 
     self.draw_rect(event, qp) 
     qp.end() 

    def draw_rect(self,event, qp): 
     #Black Rectangle 
     col = QColor("Black") 
     col.setNamedColor("Black") 
     qp.setPen(col) 

     qp.setBrush(QColor("Black")) 
     qp.drawRect(130,000,400,200) 

     #formato 
     qp.setPen(QColor("Green")) 
     qp.setFont(QFont('Helvetica', 48)) 
     qp.drawText(event.rect(), QRect(50, 50, 50, 50),5 , self.formato) # Problem 


app = QApplication(sys.argv) 
w = Window() 
sys.exit(app.exec_()) 

PD를 구축 : 다른 오류를 무시하십시오, 이것이 내가 구축하고있는 프로그램 만 조각입니다. 그리고 이것이 미숙 한 질문일지도 모른다 유감스러운. 귀하의 경우에는

void drawText(const QPointF & position, const QString & text) 
void drawText(const QPoint & position, const QString & text) 
void drawText(const QRectF & rectangle, int flags, const QString & text, QRectF * boundingRect = 0) 
void drawText(const QRect & rectangle, int flags, const QString & text, QRect * boundingRect = 0) 
void drawText(int x, int y, const QString & text) 
void drawText(int x, int y, int width, int height, int flags, const QString & text, QRect * boundingRect = 0) 
void drawText(const QRectF & rectangle, const QString & text, const QTextOption & option = QTextOption()) 

은 사용한다 :

답변

0

QPainter를 텍스트를 그릴 여러 가지 옵션을 제공합니다

qp.drawText(QPointF(50, 50), self.formato) # first option 
qp.drawText(QPoint(50, 50), self.formato) # second option 
qp.drawText(50, 50, self.formato) # fifth option 

참고 : 종료 창을 원인이 오류는 매개 변수 때문에 당신이 통과 한 것은 어떤 형식에도 해당하지 않습니다.

+0

초보자 용서에 대한 질문에 사과드립니다. –

+0

@DanielRestrepo 제 답변으로 올바른 것으로 표시하는 것을 잊어 버리지 않으면 사과 드리겠습니다. 수행 방법을 모른다면 다음 링크를 확인하십시오. [둘러보기] – eyllanesc