• 5810阅读
  • 2回复

QGraphicsItem 与QGraphicsWidget [复制链接]

上一主题 下一主题
离线ihatecoding
 
只看楼主 倒序阅读 楼主  发表于: 2012-05-18
class ImageButton : public QGraphicsWidget
{
    Q_OBJECT
public:
    ImageButton(const QPixmap &pixmap, QGraphicsItem *parent = 0);
这是构造函数的声明。

ImageButton::ImageButton(const QPixmap &pixmap, QGraphicsItem *parent)
    : QGraphicsWidget(parent), _pix(pixmap)
{}
这是cpp中构造函数。

谁能跟我解释哈,为什么通过这个构造函数就能把new出来的button绑定到Iitem了。比如:
ImageButton *btn1 = new ImageButton(QPixmap(A_PATH), buttonfather);
ImageButton *btn2 = new ImageButton(QPixmap(B_PATH), buttonfather);
ImageButton *btn3 = new ImageButton(QPixmap(C_PATH), buttonfather);

我现在想调查清楚有没有不通过构造函数来绑定到一个item里的方法。 我写的容器里已经有了的ImageButton,如何绑定到QGraphicsItem里呢?
求大神解释。
离线lwtlwt0810

只看该作者 1楼 发表于: 2012-05-18
setParentItem()
离线ihatecoding
只看该作者 2楼 发表于: 2012-05-18
回 1楼(lwtlwt0810) 的帖子
重写这个函数,我去试试!
快速回复
限100 字节
 
上一个 下一个