FAQ Database Discussion Community


Use one QPainter to paint multiple outputs at once: SVG and QImage

c++,qt,svg,qpainter,qimage
My Qt application uses a QPainter to draw a vector graphic. I need this graphic output twice, once as a vector output in SVG format, where I'm using QSvgGenerator, and once as a pixel format, where I'm using QImage. According to what I've found in the documentation I can either...

how to get the end point fo a translated QPolygon

qt,qpainter,qpolygon
Im trying to draw an arrow so I just referred to the example code where we can draw arrows. http://qt-project.org/doc/qt-4.8/graphicsview-elasticnodes-edge-cpp.html I decided to draw using the same formula and tried like theCurrentLine->setP1(QPointF(0, 0) ); theCurrentLine->setP2((theLineVector)); p->drawLine(*theCurrentLine); double angle = ::acos(theCurrentLine->dx() / theCurrentLine->length()); if (theCurrentLine->dy() >= 0) angle = TwoPi -...

What does QHeaderView::paintSection do such that all I do to the painter before or after is ignored

c++,qt,qpainter,qheaderview
This question is further development of this post and is different, though may seem similar as this one. I am trying to reimplement QHeaderView::paintSection, so that the background returned from the model would be honored. I tried to do this void Header::paintSection(QPainter * painter, const QRect & rect, int logicalIndex)...

QPainter or QLabel is less costly to draw QPixmap

qt,qpainter,qpixmap,qlabel
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");...

how to color a heart-shaped form I drew on Qt creator using c++

forms,qt,fill,qpainter
I have a little problem. I'm doing a video game in c++ using qt creator, and I would like to fill a form I drew in red. I colored the line but I can't find how to fill all the form. On the qt's doc, it explains how to fill...

Draw multiple Lines in QT

c++,qt,qpainter
I want to draw multiple lines with a application. Each line consists of three "x" values and three "y" Values, so i use QPointF with 3 points. Now i want to draw 4 lines with values from my arrays. i have two arrays. One for "x" values and one for...

Draw rich text with QPainter

qt,qstring,qpainter
is there a way to draw fixed text that has subscripts. My goal is to have something like: "K_max=K_2 . 3" QString equation="K_max=K_2 . 3"; painter.drawText( QRect(x, y , width, y+height), Qt::AlignLeft|Qt::AlignVCenter, equation); I also tried formatting the text using html tags but it didn't help (tags got printed with...

Creating and saving a picture from data stored in std::vector

c++,qt,vector,qpainter,qimage
Is there a method in Qt with which one can easily create a picture based on data stored in a std::vector? I mean that in the vector there are colors for each QPointF points of a QWidget on which I'm painting with QPainter, but I don't only need to draw...

Qt draw small 'x' icon on custom-rendered control

c++,qt,qpainter,qpainterpath
I'm drawing a custom control in Qt in the paintEvent function (so I have a QPainter to do the drawing). Now I'd like to add a small close 'x' icon that animates when the mouse is over it. I know that QPainterPath has a "contains" method that I can use...

Adjusting the selection behaviour of QStandardItem with QStyledItemDelegate

c++,qt,qpainter,qstyleditemdelegate
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...

Qt - Simple code QPrinter doesn't work on others pc

c++,qt,qpainter,qprinter
QPrinter printer(QPrinter::HighResolution); printer.setPageSize(QPrinter::A4); printer.setOrientation(QPrinter::Portrait); printer.setPageMargins (15,15,15,15,QPrinter::Millimeter); printer.setFullPage(false); printer.setOutputFormat(QPrinter::NativeFormat); QPainter painter(&printer); painter.setFont(QFont("Tahoma",8)); painter.drawText(200,200,"Test prova prova"); painter.end(); In the PC with QT the print works right (print works normally), but in the others pc (one with win 8.1 and one with win 7) doesn't start (print doesn't...

Render QGraphicsItem on QPixmap: aggregate 'QWidget w' has incomplete type and cannot be defined

c++,image,qt,qgraphicsitem,qpainter
I would like to paint items into QPixmap without painting the scene... I tried, based on this: void Item::itemPaint(QPainter *painter) { QStyleOptionGraphicsItem opt; QWidget w; paint(painter, &opt, &w); // also tried NULL } void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { .... } void caller() { QPainter* painter; for(int...

Program not drawing line with QPainter

c++,qt,qpainter
I have a program and I am attempting to draw a line on a widget. Here is the code that I have: header: #include <QWidget> #include <QtWidgets> class DrawingWidget : public QWidget{ Q_OBJECT public: explicit DrawingWidget(QWidget *parent = 0); ~DrawingWidget(); QSize minimumSizeHint() const; QSize sizeHint() const; protected: void paintEvent(QEvent *);...