qpainter

Qt: making a stacked barchart with different colors [closed]

回眸只為那壹抹淺笑 提交于 2019-12-02 08:54:44
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm trying to make a timeline in Qt, where a different color stands for a different task. Ultimately, it should look a bit like this (but only one line); Now anyone got any ideas how to do this without installing extra libraries, but just with QPaint? The data it is representing is stored in a self-defined

Qt: making a stacked barchart with different colors [closed]

大憨熊 提交于 2019-12-02 05:18:29
I'm trying to make a timeline in Qt, where a different color stands for a different task. Ultimately, it should look a bit like this (but only one line); Now anyone got any ideas how to do this without installing extra libraries, but just with QPaint? The data it is representing is stored in a self-defined structure. Any help is welcome. Thx! You seem to need something like the code below, although please note that it is just pseudo code, and the exact details depend a lot on how you get the data from your datastructure which you have not yet shared with us. ... QPainter *painter = new

Using an alpha transparent mask on a QWidget?

眉间皱痕 提交于 2019-12-02 03:41:19
问题 Is it possible to assign an alpha-transparent mask to a QWidget? I know how to set a mask using setMask but it seems it only supports black&white masks. Is it possible to make it support a true alpha channel? i.e. currently I have a PNG like this: and a widget like this: If I load my PNG in a QPixmap and set it as a mask, I get this (notice the edges): However I would like to get this (smooth edges): Any idea how to do that? Note: I'm doing some more complex drawing on the widget, which must

Using an alpha transparent mask on a QWidget?

别来无恙 提交于 2019-12-02 01:14:07
Is it possible to assign an alpha-transparent mask to a QWidget? I know how to set a mask using setMask but it seems it only supports black&white masks. Is it possible to make it support a true alpha channel? i.e. currently I have a PNG like this: and a widget like this: If I load my PNG in a QPixmap and set it as a mask, I get this (notice the edges): However I would like to get this (smooth edges): Any idea how to do that? Note: I'm doing some more complex drawing on the widget, which must be restricted to the mask area, so I cannot simply set my PNG as the widget's background image. sam-w I

How to rotate text for drawText?

喜欢而已 提交于 2019-12-01 17:52:27
I would like to rotate the text 45 degrees? QFont font; font.setPixelSize(12); //grid for(int i = 0; i < 10; i++){ painter->drawLine(100, 100 + i * 800/9, 900, 100 + i * 800/9); str = QString::number((double)9 - i, 'd', 1); painter->setFont(font); painter->drawText(75, 100 + i * 800/9 - 6, 40, 40, 1, str); } Insert painter->rotate(45); before painter->drawText(75, 100 + i * 800/9 - 6, 40, 40, 1, str); and painter->rotate(-45); after (to restore the rotation angle of the coordinate system): painter->rotate(45); painter->drawText(75, 100 + i * 800/9 - 6, 40, 40, 1, str); painter->rotate(-45);

How to rotate text for drawText?

十年热恋 提交于 2019-12-01 16:34:00
问题 I would like to rotate the text 45 degrees? QFont font; font.setPixelSize(12); //grid for(int i = 0; i < 10; i++){ painter->drawLine(100, 100 + i * 800/9, 900, 100 + i * 800/9); str = QString::number((double)9 - i, 'd', 1); painter->setFont(font); painter->drawText(75, 100 + i * 800/9 - 6, 40, 40, 1, str); } 回答1: Insert painter->rotate(45); before painter->drawText(75, 100 + i * 800/9 - 6, 40, 40, 1, str); and painter->rotate(-45); after (to restore the rotation angle of the coordinate system

How to draw a linear gradient arc with Qt QPainter?

我们两清 提交于 2019-12-01 04:02:22
I'm trying to develop a custom QProgressBar that will look like the following image : I created a class that extends QProgressBar and implemented the paintEvent() : void CircularProgressBar::paintEvent(QPaintEvent*) { int progress = this->value(); int progressInDegrees = (double)(progress*360)/100; int barWidth = 20; QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen(Qt::black, barWidth, Qt::SolidLine,Qt::RoundCap)); painter.drawArc(barWidth/2, barWidth/2, this->width() - barWidth, this->height() - barWidth, 90*16, progressInDegrees*-16);} This

How to draw a linear gradient arc with Qt QPainter?

心不动则不痛 提交于 2019-12-01 00:47:59
问题 I'm trying to develop a custom QProgressBar that will look like the following image : I created a class that extends QProgressBar and implemented the paintEvent() : void CircularProgressBar::paintEvent(QPaintEvent*) { int progress = this->value(); int progressInDegrees = (double)(progress*360)/100; int barWidth = 20; QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen(Qt::black, barWidth, Qt::SolidLine,Qt::RoundCap)); painter.drawArc(barWidth/2,

Drawing a line on a QWidget

不打扰是莪最后的温柔 提交于 2019-11-30 18:49:10
I'm attempting to create a widget that consists of of a single horizontal black line. This widget will be placed in a QGridLayout such that it takes up the entire row, thus acting as a separator. As the widget upon which the layout is installed is resized, I'd like the line to change it's size to keep up. I've checked out a number of options, including QLine, QGraphicsView and QImage, but I can't seem to get the line drawn, never mind get it to resize. I'm implementing this in it's own class so I can reuse it as and when it's needed. Can anyone please help me with this? #include

How to use QPainter on QPixmap

℡╲_俬逩灬. 提交于 2019-11-30 12:37:27
I'm a newbie to Qt/Embedded. I want to use QPainter to draw stuff on a QPixmap , which will be added to QGraphicsScene . Here is my code. But it does not show the drawings on the pixmap. It shows only the black pixmap. int main(int argc, char **argv) { QApplication a(argc, argv); QMainWindow *win1 = new QMainWindow(); win1->resize(500,500); win1->show(); QGraphicsScene *scene = new QGraphicsScene(win1); QGraphicsView view(scene, win1); view.show(); view.resize(500,500); QPixmap *pix = new QPixmap(500,500); scene->addPixmap(*pix); QPainter *paint = new QPainter(pix); paint->setPen(*(new QColor