void MainWindow::paintEvent(QPaintEvent *e) { QPainter painter(this); painter.setBrush(QBrush(Qt::red,Qt::SolidPattern)); painter.drawRect(10,10,100,100); } With this code, how do you know the color of a pixel (20,20)?
I found this method on the Internet, but it does not work
QPixmap qPix = QPixmap::grabWidget(ui->centralWidget); QImage image(qPix.toImage()); QColor color(image.pixel(20, 20));