qpixmap

Draw on top of image

本秂侑毒 提交于 2019-12-04 06:26:37
I'm new to PyQt5 and I couldn't find any answers that worked for me about how to draw with QPainter on top of a loaded image (QPixmap("myPic.png")). I tried doing it within a paintEvent method but it didn't work. If I want to draw a line on top of the loaded image in the snippet below, how would I go about doing it? import sys from PyQt5.QtWidgets import * from PyQt5.QtGui import * class Example(QWidget): def __init__(self): super().__init__() self.setGeometry(30, 30, 500, 300) self.initUI() def initUI(self): self.pixmap = QPixmap("myPic.png") lbl = QLabel(self) lbl.setPixmap(self.pixmap) self

Qt: update pixmap grid layout with 2d array values

心已入冬 提交于 2019-12-04 05:04:30
问题 I am undertaking a game using a combination of c++ in visual studios 2010 and Qt 4.7 (both windows). The game is a clone of battleship and is console input based. I have created my gui how I want it to look, and on the Qt side in Qt designer, my gui consists of a grid layout 10x10, using labels to hold pixmaps of game cells: I have painstakingly named each label to represent its position in the 2d array (ie. fleet map => F_00 => F[0,0] => F[i],[j] ). I can manually choose what pixmap I would

How to create screenshot of QWidget?

允我心安 提交于 2019-12-03 06:33:26
I work at my homework in Qt Creator, where I paint to QWidget and I need to save some part of this QWdiget. I tried to solve this problem: QPixmap pixmap; pixmap.copy(rectangle); // rectangle is part of QWidget, which I need to save pixmap.save("example.png"); Thank you for help. You can use QWidget::render for this. Assuming rectangle is a QRect: QPixmap pixmap(rectangle->size()); widget->render(&pixmap, QPoint(), QRegion(rectangle)); Very easy: QPixmap QWidget::grab(const QRect &rectangle = QRect(QPoint(0, 0), QSize(-1, -1))) s.a.: http://doc.qt.io/qt-5/qwidget.html#grab 来源: https:/

Qt: update pixmap grid layout with 2d array values

北战南征 提交于 2019-12-02 05:13:38
I am undertaking a game using a combination of c++ in visual studios 2010 and Qt 4.7 (both windows). The game is a clone of battleship and is console input based. I have created my gui how I want it to look, and on the Qt side in Qt designer, my gui consists of a grid layout 10x10, using labels to hold pixmaps of game cells: I have painstakingly named each label to represent its position in the 2d array (ie. fleet map => F_00 => F[0,0] => F[i],[j] ). I can manually choose what pixmap I would like to display using the properties editor, but I would like something dynamic. I use an update

Modify alpha channel transparency of a windowless QLabel

坚强是说给别人听的谎言 提交于 2019-12-02 02:27:40
I have a very small Qt application that uses labels to display a jpeg image without first putting it in a window. (I got a lot of help from Display QImage with QtGui ) Now I would like to change the alpha channel of this jpeg to make the image partially transparent. I have tried the following without any luck int main (int argc, char *argv[]) { QApplication app(argc, argv); QLabel label (0, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); label.resize(1280,720); label.setPixmap(QPixmap("test.jpg")); label.setScaledContents(true); // This line should set the alpha transparency to 50% label

Modify alpha channel transparency of a windowless QLabel

对着背影说爱祢 提交于 2019-12-02 01:41:23
问题 I have a very small Qt application that uses labels to display a jpeg image without first putting it in a window. (I got a lot of help from Display QImage with QtGui) Now I would like to change the alpha channel of this jpeg to make the image partially transparent. I have tried the following without any luck int main (int argc, char *argv[]) { QApplication app(argc, argv); QLabel label (0, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); label.resize(1280,720); label.setPixmap(QPixmap(

Why QPixmap::scaled() does not work?

喜夏-厌秋 提交于 2019-12-02 00:43:54
问题 I'm writing simple application by using QPixmap and QPainter. In my programm I need to load some images and resize them. I used QPixmap::scaled(), but images does not scaled. What I did wrong? This is my code: chesstile.cpp #include "chesstile.h" ChessTile::ChessTile(QWidget *parent) : QLabel(parent) { } void ChessTile::paintEvent(QPaintEvent *) { const QString &fileName = "images/white_king.png"; QPixmap bgPixmap(fileName); bgPixmap.scaled(QSize(64, 64)); QPainter painter(this); painter

Why QPixmap::scaled() does not work?

隐身守侯 提交于 2019-12-01 21:58:31
I'm writing simple application by using QPixmap and QPainter. In my programm I need to load some images and resize them. I used QPixmap::scaled(), but images does not scaled. What I did wrong? This is my code: chesstile.cpp #include "chesstile.h" ChessTile::ChessTile(QWidget *parent) : QLabel(parent) { } void ChessTile::paintEvent(QPaintEvent *) { const QString &fileName = "images/white_king.png"; QPixmap bgPixmap(fileName); bgPixmap.scaled(QSize(64, 64)); QPainter painter(this); painter.drawPixmap(0, 0, bgPixmap); } chesstile.h #ifndef CHESSTILE_H #define CHESSTILE_H #include <QLabel>

Image Viewer GUI fails to properly map coordinates for mouse press event

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 14:01:06
I am trying to piece together PyQt5 based image viewer Python code from various sources and extend capability to crop regions of interest (ROI) within loaded images. The issue is that the mapped coordinates and mouse clicks consider scroll bar and menu bar when determining pixel locations. Following is the code that loads image and provide bounding box capability, but I cannot seem to draw/crop boxes accurately due to the offset. from PyQt5.QtCore import QDir, Qt from PyQt5.QtGui import QImage, QPainter, QPalette, QPixmap from PyQt5.QtWidgets import (QAction, QApplication, QFileDialog, QLabel,

is there any way to insert QPixmap object in html?

北城余情 提交于 2019-11-30 21:56:45
Simple situation: I have an object, which has a QPixmap member. Object first created (pixmap is null now), then pixmap readed from data base and inserted in object. I need to insert that pixmap in html code () and display that html code in a QLabel but I have no idea how to make it, because pixmap's path is unknown. I know how to insert images from resource files and from files on my hard-disk, but it isn't that case. I was using QMimeSourceFactory class on qt 3.3.4, but on 4.6.2 it is deprecated. Assistant says: "Use resource system instead". But resource system compiles with app, but it is