QT5中運行QT4場景程序 QGraphicsItem *QGraphicsScene::itemAt 函數報錯的解決


#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QDebug>
#include <QGraphicsView>
#include <QPainter> //QT5 添加
#include "myitem.h"

int main(int argc,char* argv[ ])
{
    QApplication app(argc,argv);
 
        
    //新建場景
    QGraphicsScene scene;
    //創建矩形圖形項
QTransform transform;    //QT5添加
    transform.rotate(+0.0);//QT5添加
    QGraphicsRectItem *item = new QGraphicsRectItem(0, 0, 100, 100);
    //將圖形項添加到場景中
    scene.addItem(item);
    //輸出(50, 50)點處的圖形項
qDebug() << scene.itemAt(50, 50,transform);  //  QT5添加 transform
 
        
 
        
    //為場景創建視圖
    QGraphicsView view(&scene);
    //設置場景的前景色
    view.setForegroundBrush(QColor(255, 255, 255, 100));
    //設置場景的背景圖片
    view.setBackgroundBrush(QPixmap("../myScene/background.png"));
    view.resize(400, 300);
    view.show();
 
        
    return app.exec();
}
qt4中函數QGraphicsItem *QGraphicsScene::itemAt(qreal x, qreal y)
qt5中函數發生了變化

QGraphicsItem *QGraphicsScene::itemAt(qreal x, qreal y, const QTransform &deviceTransform) const

This is an overloaded function.

Returns the topmost visible item at the position specified by (x, y), or 0 if there are no items at this position.

deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations.

This convenience function is equivalent to calling itemAt(QPointF(x, y), deviceTransform).

Note: See items() for a definition of which items are considered visible by this function.

This function was introduced in Qt 4.6.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM