qpainter

Insert Image into QGridLayout and Draw on top of image in PyQt5

我只是一个虾纸丫 提交于 2019-12-12 16:18:01
问题 I'm pretty new to PyQt and am trying to make an application with a QPixmap on the left, which can be drawn on, and a QTextEdit on the right (for a simple OCR GUI). I looked at: PyQt5 Image and QGridlayout but I couldn't connect it with the code below (I'm losing my hair with all the head scratching!!) When I try adapting the following code, what I get is a QMainWindow with the QPixmap as the background which can be drawn on with the mouse and a second occurance of the QPixmap in it's correct

Qt, QTransform rotation

﹥>﹥吖頭↗ 提交于 2019-12-12 09:47:16
问题 I'm trying to draw text "on cylinder". It means, that I have five rows of text. Top row is rotated by the X axis for 10 degrees. The second for 5 degrees. The middle is not rotated at all. The four's row is rotated for -5 degrees. The five's is rotated for -10 degrees. Rows 1, 2, 3 draws OK, but something is wrong with 4,5 rows. What am I doing wrong ? I provides an image for understanding a problem and code snippet: for( int i = 0; i < iterationsCount; ++i ) { const QRect r( x2, y2,

Drawing elliptical arc with QPainter creates wrong angle

此生再无相见时 提交于 2019-12-12 05:07:01
问题 I'm working on a program which is displaying cgm graphics. For an elliptical arc, I get vectors to the start and end angles so after I calculate the angles and try to use them in an arc, I am getting the wrong angles drawn. In the image below : The gold lines show the vectors I get. The red arc is the ellipse I get trying to draw the image with the angles given. The green arc which I get is the image with the ellipse changed to a perfect circle. Is there a way I can correct this? Brief exapme

QPainter with Qt::AlignCenter does not center text correctly

三世轮回 提交于 2019-12-12 03:39:25
问题 I want to do a fairly simple drawing where I write a two pieces of text above each other in the center of the circle. My code: painter->drawText(QRectF(0, 0, m_iSize, m_iSize), Qt::AlignCenter, m_sAlias + "\n" + m_sCode); where m_iSize is the size of the circle, m_sAlias is a short text like "R1" and m_sCode is another short text like "31" . The problem is that the above code will draw both lines of text so that they are exactly ONE pixel apart horizontally. And unfortunately it is clearly

Rendering a large QGraphicsScene on a QImage clips it off

雨燕双飞 提交于 2019-12-12 01:59:12
问题 I am creating some images rendering the contents of a QGraphicsScene . My project requirement is that it should handle a canvas size of 10 ft by 8 inches. On screen, and scene size, that is 8640 x 576 pixels. I can render it fine. The thing is, the output images need to have 300 resolution. That means, the rendered image will have a width of 36000, which is over 2^15 - 1 = 32767 pixels..... The output is clipped - in the code below, I would get a QImage of correct expected size (36000) but

Why do my my line widths looks different in a QGraphicsScene with the same QPen width?

 ̄綄美尐妖づ 提交于 2019-12-11 13:12:29
问题 I use a QPainter to draw my widget with this code: QPen pen(Qt::black, 0.6, Qt::SolidLine); QPainter painter(this); painter.setPen(pen); // vertical painter.drawLine(startX,0,startX,50); painter.drawLine((startX += grid),0,startX,50); painter.drawLine((startX += grid),0,startX,50); painter.drawLine((startX += grid),0,startX,50); painter.drawLine((startX += grid),0,startX,50); painter.drawLine((startX += grid),0,startX,50); // horizontal pen.setWidth(0.7); painter.setPen(pen); painter.drawLine

Adjusting the selection behaviour of QStandardItem with QStyledItemDelegate

北战南征 提交于 2019-12-11 10:51:26
问题 I am using QStyledItemDelegate to style the items in my QTreeView . The roots of my treeview are not decorated. It's just a simple tree with relation similar to the one below: ColorBook1 Color1 Color2 ColorBook2 Color3 The parent and child are styled differently and selection on parent is disabled. I want to customise the selection behaviour in the child nodes so that the selection rectangle around the child would cover the entire row and not the text child alone. Current Behaviour: Desired

QGraphicsItem paint delay

帅比萌擦擦* 提交于 2019-12-11 07:23:07
问题 What could be the possible reason for this? When i zoom in the QGraphicsView and move the QGraphicsItem, I get this weird result. It does update if I zoom or pan the View again or if I focus on other widgets. Im using PySide. And the painter function is this def paint(self, painter, option, widget): if self.isSelected(): brush = self.highlight_brush pen = self.highlight_pen else: brush = self.dormant_brush pen = self.dormant_pen painter.setBrush(brush) painter.setPen(pen) painter.drawRect(0,

Using QPainter with QPaintDevice multiple times

天大地大妈咪最大 提交于 2019-12-11 04:49:41
问题 we all know this Warning from bool QPainter::​begin(QPaintDevice * device) Warning: A paint device can only be painted by one painter at a time. http://doc.qt.io/qt-5/qpainter.html#begin But what if I have two object sharing one pixmap, and one object Bar contains other object Foo. class Foo { public: QPixmap* barPixmap; void draw() { QPainter painter(barPixmap); painter.drawText(0,0,"FooText"); } } class Bar { public: QPixmap* barPixmap; Foo* fooObject; } and I got something like this Bar:

Why isn't the “rectangle” that I want to draw on my Qt widget showing up?

瘦欲@ 提交于 2019-12-11 03:32:42
问题 I basically want to display a rectangle on a dialog window widget. Using another question as reference, I tried to adapt the framework of using a QLabel and painting to it (the process overall seems overly complicated). I started by making a member in the dialog box's class: QLabel* label; In the constructor of the dialog box: label = new QLabel(this); label->setGeometry(20, 50, 50, 100); Just to try and make it work, I gave the dialog box a button to make the "rectangle" created with the