Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void CharacterWidget::paintEvent ( QPaintEvent event  )  [protected, virtual]

[5]

[6]

[6]

[7]

[7]

[8]

[8] //! [9]

[9]

[10]

Reimplemented from QWidget.

Definition at line 136 of file characterwidget.cpp.

References QFontMetrics::ascent(), QRect::bottom(), QPainter::drawRect(), QPainter::drawText(), QPainter::fillRect(), QWidget::fontMetrics(), QRect::left(), QPaintEvent::rect(), QRect::right(), QPainter::setClipRect(), QPainter::setFont(), QPainter::setPen(), QRect::top(), and QFontMetrics::width().

{
    QPainter painter(this);
    painter.fillRect(event->rect(), QBrush(Qt::white));
    painter.setFont(displayFont);
//! [6]

//! [7]
    QRect redrawRect = event->rect();
    int beginRow = redrawRect.top()/squareSize;
    int endRow = redrawRect.bottom()/squareSize;
    int beginColumn = redrawRect.left()/squareSize;
    int endColumn = redrawRect.right()/squareSize;
//! [7]

//! [8]
    painter.setPen(QPen(Qt::gray));
    for (int row = beginRow; row <= endRow; ++row) {
        for (int column = beginColumn; column <= endColumn; ++column) {
            painter.drawRect(column*squareSize, row*squareSize, squareSize, squareSize);
        }
//! [8] //! [9]
    }
//! [9]

//! [10]
    QFontMetrics fontMetrics(displayFont);
    painter.setPen(QPen(Qt::black));
    for (int row = beginRow; row <= endRow; ++row) {

        for (int column = beginColumn; column <= endColumn; ++column) {

            int key = row*columns + column;
            painter.setClipRect(column*squareSize, row*squareSize, squareSize, squareSize);

            if (key == lastKey)
                painter.fillRect(column*squareSize + 1, row*squareSize + 1, squareSize, squareSize, QBrush(Qt::red));

            painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.width(QChar(key))/2,
                             row*squareSize + 4 + fontMetrics.ascent(),
                             QString(QChar(key)));
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index