LayoutRect rect(10, 20, 30, 40); // x,y coordinates of top-left corner and width, height of rectangle int max_y = rect.maxY(); // get the maximum Y-coordinate of rectangle cout << "Maximum Y-coordinate of rectangle is: " << max_y << endl;
#includeThis code defines a custom QGraphicsItem called MyRect that includes a LayoutRect object to specify its position and size. It also has a getMaxY() method that returns the maximum Y-coordinate of the rectangle. The package libraries being used here are Qt, QGraphicsItem, and QPainter.#include #include class MyRect: public QGraphicsItem { public: MyRect(int x, int y, int w, int h) : m_rect(x, y, w, h) { setFlag(QGraphicsItem::ItemUsesExtendedStyleOption); } QRectF boundingRect() const override { return m_rect; } void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(widget); painter->drawRect(m_rect); if (option->state & QStyle::State_Selected) { painter->setPen(QColor(255, 0, 0, 127)); painter->drawRect(m_rect.adjusted(2, 2, -2, -2)); } } int getMaxY() const { return m_rect.maxY(); } private: LayoutRect m_rect; };