|
5Qter豆
本帖最后由 qqyypig 于 2014-3-10 14:27 编辑
如题,在场景中已经画了很多矩形(a1,a2,a3),要求符合一定的条件,比如说,当滑动鼠标滚轮放大图片的时候,在a1,a2,a3这三个矩形的下面,画一个大的矩形AA,包住a1,a2,a3,再放一张背景图片填充AA,而我现在的代码运行之后,是把背景图片放在a1,a2,a3之上的,虽然已将背景色变透明,但这样不符合要求。setZValue(5)方法,只能是将AA的边框放到下层,没办法将QPixmap 图片做为背景放到a1 a2 a3之下,而这个CfsZjItem类,就是为了画矩形AA所写的类,代码如下:- CfsZjItem::CfsZjItem(const QRectF &rect)
- : CfsItem(rect)
- {
- init();
- }
- /*!
- * \brief CfsZjItem::CfsZjItem
- * \param x
- * \param y
- * \param w
- * \param h
- */
- CfsZjItem::CfsZjItem(qreal x, qreal y, qreal w, qreal h)
- : CfsItem(x, y, w, h)
- {
- init();
- }
- /*!
- * \brief CfsZjItem::paint
- * \param painter
- * \param option
- * \param widget
- */
- void CfsZjItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
- {
- CfsItem::paint(painter, option, widget);
- if(isNeedDisplayBgImage())
- {
- //painter->drawPixmap(rect().toRect(), getBgImage());
- QPixmap pixmap = getBgImage();
- painter->setOpacity(0.5);
- painter->drawPixmap(rect(), pixmap, pixmap.rect());
- }
- }
- /*!
- * \brief CfsZjItem::getBgImage
- * \return
- */
- QPixmap CfsZjItem::getBgImage()
- {
- //return QPixmap("D:\\99_OTH\\81_Qt\\b4.jpg");
- return QPixmap(":/img_blue/Config/img_blue/zjframe.png");
- }
- /*!
- * \brief CfsZjItem::isNeedDisplayBgImage
- * \return
- */
- bool CfsZjItem::isNeedDisplayBgImage()
- {
- if(CfsView *view = cfsView())
- {
- return boundingRect().width() * view->transform().m11() > 20;
- }
- return false;
- }
- /*!
- * \brief CfsZjItem::init
- */
- void CfsZjItem::init()
- {
- setPen(QPen(Qt::yellow, 0.0, Qt::DashDotDotLine));
- setZValue(5);
- setOpacity(0.9);
- }
复制代码 我是QT初学者,C++都不懂,之前一直做java,因为项目需要才刚刚开始学习,请教各位
|
最佳答案
查看完整内容
下面的是我写的一个
QPixmap pixMap(filename);
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixMap);
pixmapItem->setZValue(0.5);
scene->addItem(pixmapItem);
|