{
public:
CCanGraphicsItem
( int x,
int y,
QString strText
) : m_rect
( 10,
10,
200,
100 ), m_color
( QColor(255,
255,
255,
255) ) {
m_strText = strText;
setPos( x, y );
}
{
// painter->setRenderHint(QPainter::Antialiasing, true);
painter->setFont( *m_pFont );
painter->setPen(Qt::SolidLine);
painter->setBrush(m_color);
painter->drawRoundRect( m_rect );//10, 10, 100, 100);
painter->drawText( 20, 20, 190, 90, Qt::AlignCenter, m_strText );//, m_rect );
}
QRectF boundingRect
() const { return m_rect;
}
protected:
{
}
{
}
};
class CCanGraphicsItem : public QGraphicsItem
{
public:
CCanGraphicsItem( int x, int y, QString strText ) : m_rect( 10, 10, 200, 100 ), m_color( QColor(255,255,255,255) )
{
m_strText = strText;
setPos( x, y );
m_pFont = new QFont("Times", 20, QFont::Bold );
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// painter->setRenderHint(QPainter::Antialiasing, true);
painter->setFont( *m_pFont );
painter->setPen(Qt::SolidLine);
painter->setBrush(m_color);
painter->drawRoundRect( m_rect );//10, 10, 100, 100);
painter->drawText( 20, 20, 190, 90, Qt::AlignCenter, m_strText );//, m_rect );
}
QRectF boundingRect() const { return m_rect; }
protected:
void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event )
{
QMessageBox::information(0, "Debug", m_strText );
}
void contextMenuEvent(QContextMenuEvent *event)
{
}
QRectF m_rect;
QColor m_color;
QString m_strText;
QFont* m_pFont;
};
To copy to clipboard, switch view to plain text mode
Bookmarks