void PiecesWidget::paintEvent (QPaintEvent *e) { int s = Pieces_.size (); QPainter painter (this); painter.setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform); if (!s) { painter.setBackgroundMode (Qt::OpaqueMode); painter.setBackground (Qt::white); painter.end (); return; } QPixmap tempPicture (s, 1); QPainter tempPainter (&tempPicture); tempPainter.setPen (Qt::red); tempPainter.drawLine (0, 0, s, 0); QList<QPair<int, int> > trues = FindTrues (Pieces_); for (int i = 0; i < trues.size (); ++i) { QPair<int, int> pair = trues.at (i); tempPainter.setPen (Qt::darkGreen); tempPainter.drawLine (pair.first, 0, pair.second, 0); } tempPainter.end (); painter.drawPixmap (QRect (0, 0, width (), height ()), tempPicture); painter.end (); e->accept (); }
void PiecesWidget::paintEvent (QPaintEvent *e) { int s = Pieces_.size (); QPainter painter (this); painter.setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform); if (!s) { painter.setBackgroundMode (Qt::OpaqueMode); painter.setBackground (Qt::white); painter.end (); return; } const QPalette& palette = QApplication::palette (); const QColor& backgroundColor = palette.color (QPalette::Base); const QColor& downloadedPieceColor = palette.color (QPalette::Highlight); QPixmap tempPicture (s, 1); QPainter tempPainter (&tempPicture); tempPainter.setPen (backgroundColor); tempPainter.drawLine (0, 0, s, 0); QList<QPair<int, int> > trues = FindTrues (Pieces_); for (int i = 0; i < trues.size (); ++i) { QPair<int, int> pair = trues.at (i); tempPainter.setPen (downloadedPieceColor); tempPainter.drawLine (pair.first, 0, pair.second, 0); } tempPainter.end (); painter.drawPixmap (QRect (0, 0, width (), height ()), tempPicture); painter.end (); e->accept (); }