2014-04-24 8 views
0

要用圓點畫圓圈我應該包含哪些內容以及應該使用哪些代碼?我試着在我的項目這個代碼不工作:在我的Qt項目中用Dash Dot畫圓圈

QPainter painter(this); 
    painter.setBackgroundColor(Qt::cyan); 
    painter.setBrush(Qt::yellow); 
    painter.drawEllipse(0,0,500,500); 

我只看到我的正常工作項目不圓或區域。請幫忙,我在哪裏寫我的代碼?在main.cpp或myproject.cpp中?非常感謝。

回答

0

您應該將代碼寫入QGraphicsItem的paint事件或QWidget的paintEvent中。您還可以使用Qt :: DashDotLine作爲筆:

void myItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 
{ 
    painter->setRenderHint(QPainter::Antialiasing,true); 
    painter->setWindow(-500,-500,1000,1000); 
    painter->setViewport(-500,-500,1000,1000); 

    painter->setPen(QPen(Qt::black, 20, Qt::DashDotLine)); 

    painter->setBrush(Qt::yellow); 
    painter->drawEllipse(-450, -450, 900, 900); 
}