【问题标题】:QGraphicsProxyWidget animations not workingQGraphicsProxyWidget 动画不起作用
【发布时间】:2015-01-08 10:51:36
【问题描述】:

我正在尝试使用 QGraphicsProxyWidget 执行一些动画,但没有看到任何正在应用的动画。例如,如果我只想旋转 QGraphicsTextItem,则此代码有效:

      QGraphicsView *view_ = new QGraphicsView(this);          
      QGraphicsScene *scene_ = new QGraphicsScene(view);
QGraphicsTextItem *text_item_ = new QGraphicsTextItem("This is some sample text to\ntest if we can rotate the\nimage correctly");
      scene_->addItem(text_item_);
      text_item_->rotate(180);
      view->setScene(scene_);

然而这实际上似乎并没有做任何事情:

      QLabel* label =  new QLabel(this);
      label->setText("This is some sample text to\ntest if we can rotate the\nimage correctly");
      QGraphicsView *view_ = new QGraphicsView(this);          
      QGraphicsScene *scene_ = new QGraphicsScene(view);
QGraphicsProxyWidget *proxy_widget_ = new QGraphicsProxyWidget();
      proxy_widget_->setWidget(label);
      scene_->addItem(proxy_widget__);
      proxy_widget_->rotate(180);
      view->setScene(scene_);

也不是这样:

QGraphicsProxyWidget *proxy_widget_ = scene_->addWidget(label).

有什么建议吗?

【问题讨论】:

    标签: c++ qt qgraphicsview qt4.7


    【解决方案1】:

    您的代码添加代理小部件并调用:-

    proxy_widget->rotate(180);
    

    如果您查看 QGraphicsProxyWidget 文档,您会发现它继承自 QGraphicsItem,并且您应该调用函数 setRotation

    proxy_widget->setRotation(180);
    

    【讨论】:

      【解决方案2】:

      谢谢梅林。想通了这个问题。如果您从 QLabel 中删除育儿,它会起作用。

      所以改变这个:

      QLabel* label =  new QLabel(this);
      

      到这里:

      QLabel* label =  new QLabel();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-03
        • 2017-08-18
        • 2018-09-27
        • 2011-02-01
        相关资源
        最近更新 更多