2017-12-03 16 views
0

座標を含むテキストを配置しようとしていますが、引数の導入方法がわかりません。 ネットで検索したところ、Qt.Allign ----の例しかなかったので、ドキュメントのように引数を置くとエラーになりました。 これは、PD drawText()で座標を含むテキストを配置する

pythonでPyQt5で3.6

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_()) 
が構築されています:他のエラーを無視してください、これは私が構築していたプログラムからの断片のみです。これは初心者の質問かもしれないと申し訳ありません。あなたのケースでは

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

関連する問題