The code below loads an image using QLabel. The code uses: myLabel.setMask(pixmap.mask()); and it works as it should. The problem comes when I try and load an image using QGraphicsScene.
#include <QApplication> #include <QLabel> #include <QtGui> int main(int argc, char *argv[]) { QApplication app(argc, argv); QLabel myLabel; QPixmap pixmap("/path/tomy/image.jpg"); myLabel.setPixmap(pixmap); myLabel.setMask(pixmap.mask()); myLabel.show(); return app.exec(); }In this code I am attempting to the same as above but using QGraphicsScene. The pixmap is loaded properly, after that I am not sure why the program is not working properly. Is it because there is no setMask() operation? Or is there an operation missing that is needed to make the image visible?
#include <QtGlobal> #if QT_VERSION >= 0x050000 #include <QtWidgets> #else #include <QtGui> #endif int main(int argc, char *argv[]) { QApplication a(argc, argv); QPixmap pixmap("/path/tomy/image.jpg"); QGraphicsPixmapItem item( pixmap); QGraphicsScene* scene = new QGraphicsScene; scene->addItem(&item); QGraphicsView view(scene); view.show(); return a.exec(); }
Having trouble drawing an image in Qt using QGraphicsScene
488 Views Asked by Aborg At
0
There are 0 best solutions below
Related Questions in QT
- C++ template using pointer and non pointer arguments in a QVector
- Using QPointer and QObject::connect with C++11
- qt How to style a QToolBar > QToolButton overflow button?
- Qt - Repeatedly write at beginning of file
- C++ Mongodb driver, not working
- deletion and cleanup of worker thread in Qt crashes
- How to drap item from QTableView to QPushButton?
- get image type from qimage
- C++ QT Getting part from QString
- How to connect a destroyed signal of C++ object from QML?
- How to get shader version from QOpenGLShader?
- Size of Qt QRadioButton able to get smaller, but not larger than default
- error WinSock.h has already been included Boost Windows Qt
- How to call a non-class member function with pointers as parameters with QtConcurrent::run?
- What is the difference between MinGW SEH and MinGW SJLJ?
Related Questions in QGRAPHICSSCENE
- QGraphicsScene on a QMainWindow
- Qgraphicsview items not being placed where they should be
- Deleting an item from a scene
- Selecting several items and then taking distance between them
- what is the best way to convert a Qt object(QgraphicsItem) into C++ class object
- mousePressEvent not working as expected in QGraphicsScene
- Qt GraphicsScene on Widget
- QGraphicsScene::removeItem: item scene is different from this scene
- Zooming in a QGraphicsScene makes my drawings disappear sometimes
- Smoothly Updating QGraphicsscene
- Error while making arc
- how to find an item in the scene
- Arc in QGraphicsScene
- Error: Cannot allocate an object
- Snapping in grid using qt
Related Questions in QPIXMAP
- Qt - load bmp565 into QPixmap
- PyQt4: Graphics View and Pixmap Size
- Getting Pixmap is a null pixmap on calling a function 500 times
- How to convert QVector<double> to QBytearray then display it via QPixmap?
- Zooming in a QGraphicsScene makes my drawings disappear sometimes
- QPixmap's loadFromData function used some strange mechanism for cache?
- QGraphicsView shows artifacts after opening file dialog
- using QPixmapCache to speed up the performance
- Create QR-code in Python (PyQt)
- How to export a PyQt5 QGraphicsScene which contains several QPixmapItems as an image?
- How to draw a red 'X' in a specific coordinate by clicking in a qlabel with a pixmap using pyqt5?
- Showing Consecutive images on a QLabel PyQt4
- Qt QPixmap QPainter problem
- I am not using QPixmap, in PyQt. but I get QPixmap: It is not safe to use pixmaps outside the GUI thread in PyQt
- Loading an image onto a graphics view from a byte array
Related Questions in QLABEL
- QWidget.paintevent() vs QLabel.setPixmap()
- Remove Labels in qt
- Python PyQt Qlabel Resize
- How do I modify a QLabel object in my UI outside of its slot?
- Not able to display Qlabel on PyQt4
- Make a QLabel blink
- QListWidgetItem items overlap each other
- How to make QLabel expand width geometry to accommodate text
- How to insert QPushButton into a QLabel (PyQt4)?
- Want to execute a QString statement, which has the last part as integer variable
- How can I access the text contained in QLabel using a loop?
- How to get the text from QTableWidget::setCellWidget()
- Qt: display an image (QLabel) inside a QScrollArea
- How to get the text color of a QLabel?
- displaying a text using QLabel ontop of another QLabel showing image has become such a pain
Related Questions in QGRAPHICSPIXMAPITEM
- Move a QGraphicsPixmapItem through keyboard
- How to rotate an QGraphicsPixmapItem in Qt
- How can I achieve semi-transparent overlapping regions in QGraphicsItems?
- Scaling-Rotating functionality on QGraphicsPixmapItem
- MouseOver very slow when using QGraphicsView and many QGraphicsPixmapItem in QT6.4 and C++
- How to add visual effects on QGraphicsPixmapItem?
- Qt: how to make QGraphicsPixmapItem automatically move in a repeating route
- QT: cannot set position of an object in mainwindow even after static_cast
- PyQt5 pixel level collision detection
- Qt QGraphicsProxyWidget hiding other QGraphicsProxyWidgets
- QGraphicsPixmapItem - trigger only event of the top object
- QGraphicsPixmapItem: No such file or directory ^
- Qt: Signals and Slots in QGraphicsPixmapItem class
- How to draw a border / outline around a QPixmap
- Simplifying a Qt program and I am having trouble displaying an image in Qt using QGraphicsScene
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?