2016-03-30 11 views
0

ここに2つの黒塗りがあります。 の絵は、QPainter(上書き::paintEvent(...))を使って行った。右側のウィジェットはQStyleSheetを使用して「ペイント」されました。Qt QPainter対QStyleSheetsを使用したアンチエイリアス

enter image description here

この作品はPyQt4(Python: 2.7.11+/Qt: 4.8.7/PyQt4: 4.11.4)で行われました。しかし、私はPyQt5とC++ Qt4/Qt5を使って同じ結果を達成しました。

I左QWidgetをペイントするために使用されるコードは、2つの間に差がある理由右ウィジェットを使用

def paintEvent(self, pEvent) : 

    painter = QPainter(self) 
    painter.setRenderHints(QPainter.HighQualityAntialiasing) 

    painter.setPen(Qt.black) 
    painter.setBrush(Qt.black) 

    painter.drawRoundedRect(self.rect(), 10.0, 10.0) 

    painter.end() 

    pEvent.accept() 

スタイルシートは、特に丸み部が描か

setStyleSheet("border-radius: 10px; border: 1px solid black; background: black;") 

ありますQStyleSheetQPainter.HighQualityAntialiasingレンダリングヒントを使用しても、QPainterよりもはるかに滑らかですか? QPainter.AntialiasingまたはQPainter.TextAntialiasingを使用しても状況は改善されません。

答えて

1

QPenを初期化するために色を使用すると、ペン(したがってその境界線)の幅が0になります。私の推測では、同じ結果を得るためにはスタイルシートのように1pxに設定するべきです。

painter.setPen(QPen(Qt.black, 1)) 

を編集してみてくださいを私はちょうどQLabel秒間丸いボーダーを実装、私のいくつかの古いコードについて来ました。私はQRectペンの幅を修正することを余儀なくされました。さもないと、私は同様に醜い結果を得ました。実装はカスタムスタイルに置かれます。影の色は適切なフレーム色に設定されます。

void MyStyle::drawControlHeaderFrame(const QStyleOptionFrameV3* option, 
    QPainter* painter, const QWidget* widget) const 
{ 
    QPalette::ColorGroup cg = QPalette::Active; 

    if(!(option->state & QStyle::State_Enabled)) 
     cg = QPalette::Disabled; 
    else if(!(option->state & QStyle::State_Active)) 
     cg = QPalette::Inactive; 

    const int lineWidth = 2, frameAdjustment = lineWidth/2; 
    QRect rect(option->rect); 
    //Adjust for pen width 
    rect.adjust(frameAdjustment, frameAdjustment, -frameAdjustment, -frameAdjustment); 

    QPen pen(option->palette.color(cg, QPalette::Shadow)); 
    pen.setWidth(lineWidth); 

    painter->save(); 
    { 
     painter->setRenderHint(QPainter::Antialiasing); 
     painter->setPen(pen); 
     painter->drawRoundedRect(rect, 9, 9); 
    } 
    painter->restore(); 
} 
+0

いいえ。私はデフォルトの幅が1だと思う。幅0と2を試しました。絶対に変更はありません。 – Marcus

+0

実際に、あなたが提案しているこのコードでも同じ結果が得られます。ここに実装のスクリーンショットがあります:http://i.imgur.com/ylK0YkH.jpg – Marcus

関連する問題