qpainter

Draw rich text with QPainter

最后都变了- 提交于 2019-11-28 08:30:00
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 the text): QString equation="<p>K<sub>max</sub></p>=<p>K<sub>2</sub></p>.3" Here is a full example using rich text of QTextDocument. mainWindow.cpp: #include "mainWindow.h" void MainWindow::paintEvent(QPaintEvent*) { QPainter painter(this); QTextDocument td; td.setHtml("K<sub

How to rotate a QPushButton?

风流意气都作罢 提交于 2019-11-28 04:07:12
问题 I would like---with Python and Qt4---to rotate a QPushButton (or at least its text) so it can stand vertically. I've seen some documentation online, but I couldn't make much sense out of it---it's in C and I'm C-illiterate. From what I read though, one needs to re-implement the paintEvent() handler, instantiate and rotate a QPainter(). What I can't figure out however is how to do this for the one QString or QPushButton I need only. I assumed the QPaintEvent would have a "sender" attribute,

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

给你一囗甜甜゛ 提交于 2019-11-28 01:34:18
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) const { QVariant bg = model()->headerData(logicalIndex, Qt::Horizontal, Qt::BackgroundRole); // try before if(bg.isValid()) // workaround for Qt bug https://bugreports.qt.io/browse/QTBUG-46216 painter->fillRect(rect, bg.value<QBrush>()); QHeaderView::paintSection(painter

Qt : Smooth a circular mask. Remove Jagged edges

独自空忆成欢 提交于 2019-11-27 07:18:13
问题 I am currently doing the following for putting a circular mask on my image. As a result only circular region of my image is displayed.This works fine however the image tends to have jagged edges (border). Any suggestion on how I could do this. 回答1: From the documentation of QPixmap you can learn: The hasAlpha(), setMask() and mask() functions are legacy and should not be used. They are potentially very slow. Apart from being slow, they operate on a binary mask ( QBitmap ) which does not

How to align QPainter drawText around a point, not a rectangle?

烂漫一生 提交于 2019-11-27 02:42:49
问题 I want to set text drawing alignment using one point as coordinate, not a rectangle. As far as I understand QPainter::drawText allows to set text alignment only when I pass coordinates as rectangle. How can I set text alignment if I wish to align the text relative to a point, not in a rectangle? 回答1: When you pass a starting point for drawing text, you're effectively drawing text on an a large rectangle that has the bottom-left corner at the given point. So all you need is to offer a suitable

paintEvent in QTableView derived class: Paint device returned engine == 0, type: 1

偶尔善良 提交于 2019-11-26 14:48:36
问题 As a follow up of Qt load indicator by animated image (aka preloader) or alternative? I try to paint inside a QTableView . But when I initialize the QPainter I get the following warnings. QWidget::paintEngine: Should no longer be called QPainter::begin: Paint device returned engine == 0, type: 1 Here is the code (SO answer, with a button it seems to work): void CDerivedFromQTableView::paintEvent(QPaintEvent *event) { QTableView::paintEvent(event); // draw original content QPainter p(this); //