QPushButton* pButton = new QPushButton(“Click Me”); QRect rect = pButton->geometry(); int x = rect.x(); int y = rect.y(); int width = rect.width(); int height = rect.height();
QPainter painter(this); QRect rect(50, 50, 100, 100); painter.drawRect(rect);In this example, we create a QPainter object and use the QRect function to define a rectangle with x=50, y=50, width=100, and height=100. We then use the drawRect function to draw the rectangle on the screen. Overall, QRect is a useful function for GUI programming and is a part of the Qt Library.