qpainter

Qt drawRect in background

筅森魡賤 提交于 2019-12-06 04:13:19
问题 I want to paint the background of a slider. I tried this but the color covers up the whole slider. This is in an inherited class of QSlider void paintEvent(QPaintEvent *e) { QPainter painter(this); painter.begin(this); painter.setBrush(/*not important*/); // This covers up the control. How do I make it so the color is in // the background and the control is still visible? painter.drawRect(rect()); painter.end(); } 回答1: To set the background of a widget you could set the style sheet: theSlider

QPainter::drawText, get bounding boxes for each character

[亡魂溺海] 提交于 2019-12-05 21:54:57
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' , instead of being to the right of 'e' , because of the newline. Something like the coordinates of the

Sharing OpenGL VAO/VBO/etc. via QGLWidget

喜欢而已 提交于 2019-12-05 13:33:50
I am using a 3 layer hierarchy of QGLWidgets to share shaders and vertex data between 5 OpenGL viewports in my CAD-like app. The root context is used for compiling application-wide shaders, the per document context is used to share model vertex data, and the viewport contexts are the ones that actually do the rendering (and also contain grid vertex data and other per viewport stuff). The shader sharing seems to work fine, and so does the grid drawing, but when it comes to sharing vertex data it fails and to be honest - I cannot see how it is supposed to work... I built a 3D icon for an item

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

↘锁芯ラ 提交于 2019-12-05 06:55:37
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 don't succeed to add transparency to an opaque image like I want. Could anyone point me to a working

Stroking a path only inside/outside?

核能气质少年 提交于 2019-12-05 01:15:42
问题 Given a QPainterPath how can I stroke the path only on the inside or outside edge of the path (or left- or right-side for non-closed paths)? QPainter::strokePath() centers the pen along the path and causes the same amount of ink to fall on both sides. For a visual example of the desired effect, see this graphic I made (for an SVG proposal, not feature): I don't mind if this is done through some hack like setting the path itself as a clipping region (for inside) or anti-clipping region (for

How to draw and fill a triangle with QPainter?

你说的曾经没有我的故事 提交于 2019-12-04 21:54:42
问题 This is what I tried, it gave me no output. Where am I going wrong? // Start point of bottom line qreal startPointX1 = 600.0; qreal startPointY1 = 600.0; // End point of bottom line qreal endPointX1 = 600.0; qreal endPointY1 = 1200.0; // Start point of top line qreal startPointX2 = 600.0; qreal startPointY2 = 600.0; // End point of top line qreal endPointX2 = 800.0; qreal endPointY2 = 1200.0; QPainterPath path; // Set pen to this point. path.moveTo (startPointX1, startPointY1); // Draw line

Using QtConcurrent to load a Pixmap and paint it

送分小仙女□ 提交于 2019-12-04 17:25:14
I'm trying to create a Tile rendering program. Heres some basic code. Header class Tile: public QGraphicsItem { public: Tile(void); ~Tile(void); QGraphicsPixmapItem *tileItem; void update(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget); protected: QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget); }; CPP: .Constructor etc . . void Tile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) { if(tileItem==NULL) { qDebug()<<"Loading Pixmap"; QPixmap p("c:\\qt\\tile\\tile0-0.png"

Using QPainter to draw a line between QWidgets

半腔热情 提交于 2019-12-04 15:01:26
I'm working on an application where I need to be able to draw a line between two QWidget objects. I have tried quite a few things, but my current attempt (which I think is in the right direction I just think I'm missing something) is to have the containing widget (which I called DrawWidget and which holds the QGridLayout that the QWidget objects are added to) override the paintEvent method and call the QPainter::drawLine() function. The issues I'm having are that: No matter how I try to get the position of the widgets, the endpoints of the line are always in the wrong place Whenever I try to

How to disable multiple auto-redrawing at resizing widgets in PyQt?

走远了吗. 提交于 2019-12-04 13:36:17
问题 I have a PyQt4 program with widgets whose content redraws very slowly (it's ok, because of my tasks). And when I trying to resize those widgets, program is trying to redraw a lot of times while mouse is not released. That's a lot of freezes. I want to disable that auto-redrawing and configure PyQt to redraw all widgets only when mouse is released (which means that redraw happens exactly one time per one resize). How to do that? Edit1. I'll see it quite simply, like this: you drag the line,

Qt drawRect in background

走远了吗. 提交于 2019-12-04 10:12:45
I want to paint the background of a slider. I tried this but the color covers up the whole slider. This is in an inherited class of QSlider void paintEvent(QPaintEvent *e) { QPainter painter(this); painter.begin(this); painter.setBrush(/*not important*/); // This covers up the control. How do I make it so the color is in // the background and the control is still visible? painter.drawRect(rect()); painter.end(); } To set the background of a widget you could set the style sheet: theSlider->setStyleSheet("QSlider { background-color: green; }"); The following will set the background of the widget