C++ (Qt)void MainWindow::mouseMoveEvent(QMouseEvent *event){ stopPosition = event->pos(); //rect = QRect(startPosition.x(),startPosition.y(),event->pos().x(),event->pos().y()); rect.setTopLeft(startPosition); rect.setBottomRight(stopPosition); update();} void MainWindow::paintEvent(QPaintEvent *event){ qDebug() << "painter" << startPosition << stopPosition; QPainter painter(this); QPen pen; pen.setColor(Qt::blue); pen.setWidth(1); painter.setPen(pen); painter.setBrush(QBrush(Qt::blue)); painter.setOpacity(0.5); // if (stopPosition.x() < startPosition.x())// ...............................................................// }else painter.drawRect(rect); pen.setColor(Qt::black); pen.setWidth(6);