qpixmap

PyQt: Create QPixmap with alpha channel and not premultiplied color channels

纵然是瞬间 提交于 2019-12-10 20:06:10
问题 I would like to create a QPixmap to draw on using a QPainter. The QPixmap should support transparency without using premultiplied color channels. Currently I do this by creating a QPixmap with the desired dimensions and filling it with a QColor that has been set to zero for each channel (including alpha). tex = QtGui.QPixmap(width, height) c = QtGui.QColor(0) c.setAlpha(0) tex.fill(c) This adds transparency to the QPixmap. However, if I draw to the QPixmap using a QPainter, the drawn color

Drawing a line with a pixmap brush in Qt?

跟風遠走 提交于 2019-12-10 19:38:30
问题 For some time I'm developing a simple drawing and painting app with Qt/C++. Currently I'm using QPainter::drawLine() to draw, and it works fine. What I want to do is drawing with pixmap brushes, which in a way I can do. I can draw with single color filled pixmaps using QPainterPath and QPainter::strokePath(). I stroke the path with a pen using a brush with the pixmap. In case you're still reading, my problem is, if I use a QPen and QPainter::strokePath() I get a line with tiled brush. But I

Load QPixmap from QByteArray in Qt?

风格不统一 提交于 2019-12-10 12:59:05
问题 I have a byte array with the contents of an image (in png/bmp or some other format). How can I load it into a QPixmap? 回答1: bool QPixmap::loadFromData ( const QByteArray & data, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor ) Format here is string literal like "PNG" or something similar QPixmap p; QByteArray pData; // fill array with image if(p.loadFromData(pData,"PNG")) { // do something with pixmap } 回答2: You should use the folowing, where your bytes are in the

how to remove extra margins arounding a QPixmap?

坚强是说给别人听的谎言 提交于 2019-12-10 10:29:13
问题 I draw a QRectF in the paint function of my class and set a QPixmap as brush for it. I build an object from a class containing this QRectF . When I put this item in my scene and set background for the scene the QRectF appears. It also occurs for a QPixmap that I add to the scene. What can I do to remove the extra margins? void MyQgraphicsObject::paint(QPainter *painter, ) { QRectF rec(0,0,50,60); QPixmap pi(":picture/im/super.jpg"); pi=pi.scaled(50,60); painter->setBrush(QBrush(pi)); painter-

Choppy scrolling of QPixmap using Qt Animation Framework

江枫思渺然 提交于 2019-12-08 14:28:24
问题 I created QPropertyAnimation and connected it to my SonogramWidget that scroll a long picture vertically on animation events. The 'long picture' is composed of 100 pre-calculated QPixmap objects 1024x128 placed one after another vertically. They displayed in SonogramWidget::paintEvent() with QPainter . Drawing procedure paint not all QPixmap at once, but only visible of them, considering widget height and current vertical offset. CPU is almost free, because QPixmap is a fastest way to display

Saving QPixmap to JPEG failing (Qt 4.5)

試著忘記壹切 提交于 2019-12-07 11:47:02
问题 I have the following code. QString fileName = QFileDialog::getSaveFileName( this, tr("Output Image file"), (""), tr("PNG (*.png);;JPEG (*.JPEG);;Windows Bitmap (*.bmp);;All Files (*.*)") ); if(fileName != "") { QwtPlot* pPlot = ... QSize size = pPlot->size(); QRect printingRect(QPoint(0, 0), size); QPixmap pixmapPrinter(size); pixmapPrinter.fill(Qt::white); { QPainter painter(&pixmapPrinter); pPlot->print(&painter, printingRect); } bool isOk = pixmapPrinter.save(fileName); if(!isOk) { QString

Scaled QPixmap looks bad

邮差的信 提交于 2019-12-07 09:10:05
问题 I have the following widget: pixmap = QtGui.QPixmap(r'pics\cdaudio.png').scaled(100, 100) The image is scaled down, from 256x256. It looks pretty choppy: How can I scale it smoothly from within Qt? 回答1: Use the transformMode parameter: pixmap = QtGui.QPixmap(r'pics\cdaudio.png').scaled(100, 100, transformMode=QtCore.Qt.SmoothTransformation) 回答2: According to @iTayb, here's what I came up with: // Scale the source to the requested size with // the KeepAspectRatio as aspectMode &

How to make qt qgraphicsview scale to not affect stipple pattern?

孤者浪人 提交于 2019-12-07 03:54:30
问题 I draw few rectangles inside the QGraphicsView ; I use custom stipple pattern for these by creating a QBrush with my QPixmap . This gets displayed with the default zoom level as expected. When I call view->scale() , the rectangles show up bigger or smaller as I expected. However Qt has scaled the individual bits of the stipple pattern which is not expected; I expected it to draw the larger or smaller rectangle again with the brush. Eg. If I had used a stipple pattern with one pixel dot and

QPixmap and SVG

雨燕双飞 提交于 2019-12-06 11:36:04
问题 How would you suggest to handle svg with QPixmap? The construct QPixmap(":/myfile.svg"); then call of scaled() does not work. The QPixmap gets pixelised. Thx. 回答1: You should use SVGRenderer to render it onto a QImage . From there you can convert to a QPixmap with QPixmap::convertFromImage . 回答2: Now there is much simpler way without needing of SVG module QIcon("filepath.svg").pixmap(QSize()) So simple and works fine. Atleast in my case it worked. 回答3: Something like that: QSvgRenderer

High performance QImage output to display

a 夏天 提交于 2019-12-06 06:37:58
问题 I'm trying to make video output (sequence of frames) to any qt visible widget. At beginning i thought that QLabel will be enough for this point... but i was wrong. Converting to pixmap is too overloading for processor at large images: 1080p for example. Any other solution? (not QLabel?) Example of code for one frame: QImage m_outputFrameImage(width, height, QImage::Format_RGB888); memcpy(m_outputFrameImage.bits(), m_frameRGB->data[0], height * width * 3); QPixmap pixmap = QPixmap::fromImage(m