如果我将从RGB QImage创建的QPixmap添加到QGraphicsScene并设置它的ItemIsMovable标志,我可以拖动它。但是,如果我尝试对RGBA图像执行相同操作,则无效。
#include <QtGui>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPixmap>
#include "form.h"
Form::Form(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
// Doesn't work
//QImage image(20,20, QImage::Format_ARGB32);
//QColor black(0,0,0, 122);
//image.fill(black.rgba());
// Works
QImage image(20,20, QImage::Format_RGB32);
QColor black(0,0,0);
image.fill(black.rgb());
QGraphicsScene* scene = new QGraphicsScene;
QGraphicsPixmapItem* item = scene->addPixmap(QPixmap::fromImage(image));
item->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
this->graphicsView->setScene(scene);
}
为了能够在场景中拖动RGBA项目,我还需要做些什么吗?