qpainter

Why does QPainter::drawPoint draw a horizontal line segment?

安稳与你 提交于 2019-12-11 02:23:57
问题 I'm trying to draw a 3-pixel large point with QPainter . But the following code instead draws a horizontal line with width of 3 pixels. #include <QPainter> #include <QImage> int main() { const int w=1000, h=1000; QImage img(w, h, QImage::Format_RGBX8888); { QPainter p(&img); p.fillRect(0,0,w,h,Qt::black); p.scale(w,h); p.setPen(QPen(Qt::red, 3./w, Qt::SolidLine, Qt::RoundCap)); p.drawPoint(QPointF(0.1,0.1)); } img.save("test.png"); } Here's the top left corner of the resulting image: I am

Change origin point of QPainter

走远了吗. 提交于 2019-12-11 02:07:17
问题 By default QPainter has its origin point in top-left corner. I want to draw shapes but all coordinates that I have are in cartesian system. So my question - how can I change the origin point to bottom-left corner? Sure, I can scale(1,-1) but then drawText() also scaled and prints inverted text. All I nee it just move origin point. 回答1: QPainter painter(this); painter.translate(this.rect().bottomLeft()); painter.scale(1.0, -1.0); 回答2: You can use void QPainter::translate ( const QPointF &

Coordinate scaling causes too large font sizes in QPainter::drawText

∥☆過路亽.° 提交于 2019-12-10 23:05:13
问题 I'm working on simple 2D visualization module for MD simulation code. What I'm trying to do is drawing positions of simulated molecules using: myPainter.drawEllipse(myQPoint,myRx,myRy) And that part works pretty good on my visualization widget. The thing that happened to be a problem is writing text which should represent each molecule's ID (integer). myPainter.drawText(myPosPoint,QString::number(mySoftMolecule2D->getID())); It draws text but it is too large. This is probably because I need

QPainter or QLabel is less costly to draw QPixmap

半城伤御伤魂 提交于 2019-12-10 22:38:08
问题 I have to create an Icon pixmap, two methods I am familiarized to do that, One is setting the pixmap as o QLabel and display it, and other is drawing pixmap using QPainter , ie Method one Icon::Icon { QLabel iconLab = new QLabel; QLabel iconName = new QLabel; iconLab->setPixmap("mypixmap.png"); iconName->setText("myiconname"); QVBoxLayout *iconLayout = new QVBoxLayout; iconLayout->setMargin(0); iconLayout->addWidget(iconLab, 1, Qt::AlignCenter); iconLayout->addWidget(iconName, 1, Qt:

Rich text to image in QT

自古美人都是妖i 提交于 2019-12-10 18:02:23
问题 In my application , have a QTextEdit dialog that accepts Rich Text Input. I need to convert this input in to an image for some purpose . If it was Plain text i could use DrawText associated with the QPainter class . But Rich text cannot be dealt the same way as we don't know the formatting done. Any suggestions on how to convert ? 回答1: You may use QTextEdit::document + QTextDocument::drawContents. You don't need any hacks with rendering widgets, as proposed by other authors, because there may

Intersection point of QPainterPath and line (find QPainterPath y by x)

谁说我不能喝 提交于 2019-12-10 16:45:32
问题 I have QPainterPath. I need to find y coordinate of QPainterPath by x. I found intersected() method in QPainterPath. So, I created new QPainterPath, which is line from left to right edge of my path's bounding rect with x coordinate, to find point as result of intersection. intersects() method returns true. But intersected() returns empty path. Everything works If I use rect with height = 1 instead of line. Maybe you have a better idea how to find intersection of QPainterPath with line? 回答1:

Qt painting without clearing the background

妖精的绣舞 提交于 2019-12-10 14:43:06
问题 I'm using a QPainter to get some graphics on a window. Unfortunately every time the paintEvent() function is called, the whole window is cleared. How can I draw without clearing? I.e. how do I leave the stuff from previous paint event untouched? I'm using Qt4 回答1: You need to set the backgroundMode by using the setBackgroundMode setter. The Qt::NoBackground enum is what you are searching for. 回答2: Since both replies are for Qt3 only, here is the solution for Qt4. You need to call setAttribute

How to trace the missing pixels when using drawLine

孤人 提交于 2019-12-10 12:17:52
问题 We know that for drawing on an image in qt, qpainter is used. Recently, I used drawLine() function to draw whatever an user is scribbling. This was done by passing the lastPoint and currentPoint from the mouseMoveEvent to a custom function which implements drawLine(). I have passed the arguments for that custom function as given below: void myPaint::mouseMoveEvent(QMouseEvent *event) { qDebug() << event->pos(); if ((event->buttons() & Qt::LeftButton) && scribbling) { pixelList.append(event-

QPainter::drawText, get bounding boxes for each character

核能气质少年 提交于 2019-12-10 10:08:22
问题 I'm using QPainter to draw multiline text on QImage. However, I also need to display a colored rectangle around each character's bounding box. So I need to know the bounding box that each character had when being drawn. For example, for painter.drawText(QRect(100, 100, 200, 200), Qt::TextWordWrap, "line\nline2", &r); I would need to get 10 rectangles, taking into account newlines, word-wrap, tabs, etc. For example, the rectangle of the second 'l' would be below the rectangle of the first 'l'

How to make a QImage or QPixmap semi-transparent - or why is setAlphaChannel obsolete?

微笑、不失礼 提交于 2019-12-10 04:19:17
问题 4.7 and like to overlay two images on a qgraphicsview. The image on top shall be semi-transparent to allow to see through it. Initially both images are fully opaque. I expected some function for setting a global alpha-value for each pixel to exist, but it seems like there is no such function. The closest thing to it is QPixmap::setAlphaChannel(const QPixmap & alphaChannel), which, however, is marked as obsolete since Qt-4.6. Instead the manual refers to the CompositionModes of QPainter, but I