qpainter

How to use QPainter in a QWidget in PyQt4

二次信任 提交于 2020-01-09 03:56:11
问题 My code below currently opens a 500x500 QMainWindow that is blank. I am simply trying to draw a circle in the QWidget using QPainter. Here is my code: from PyQt4 import QtCore, QtGui, Qt from PyQt4.QtGui import QApplication, QMainWindow import sys class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.resize(500, 500) self.centralwidget = QtGui.QWidget(MainWindow) self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget) MainWindow.setCentralWidget(self.centralwidget) self

How can QPainter performance be improved?

我与影子孤独终老i 提交于 2020-01-05 12:58:35
问题 I have a large display (about 1000x2000 pixels) and I'm doing the following to draw images to the screen: QImage *pImage = GetImage(); // from wherever QPainter painter(this); painter.drawImage((0,0), *pImage); // this line takes over 100ms to complete. The larger the screen is that I'm drawing to, the longer this paint takes. I guess the pImage is being memcpy'd and that's the difference. How can I reduce this overhead? I'm not trying to scale or anything here. Thanks. 回答1: You're painting a

CutyCapt issue with SSL URL

偶尔善良 提交于 2020-01-03 01:28:07
问题 I am having a problem getting CutyCapt to work with SSL URLs, I have the most recent version of CutyCapt ( CutyCapt.cpp 10 2013-07-14 21:57:37Z ), it works perfect with all non-SSL URLs, when I try to grab a URL with SSL using the following command: ./xvfb-run ./CutyCapt --min-width=1280 --min-height=720 --max-wait=6000 \ --url="https://apple.com" --out="testssl.jpg" I get the following error: QPainter::begin: Paint device returned engine == 0, type: 3 QPainter::setRenderHint: Painter must be

Warning QPainter inside paintEvent [duplicate]

两盒软妹~` 提交于 2019-12-31 06:18:09
问题 This question already has an answer here : paintEvent in QTableView derived class: Paint device returned engine == 0, type: 1 (1 answer) Closed 2 months ago . I tried to draw some more information in QChartView so I re-implement paintEvent virtual void paintEvent(QPaintEvent *event) { QChartView::paintEvent(event); OmenChart *mchr = dynamic_cast<OmenChart *>(this->chart()); if(mchr == nullptr) return; QPainter painter(this); const int labelOffset = 2 + 2; painter.setFont(this->font());

Drawing a line on a QWidget

女生的网名这么多〃 提交于 2019-12-30 06:11:07
问题 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

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

此生再无相见时 提交于 2019-12-28 06:51:22
问题 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

How to center QPixmap while Painting it inside QItemDelegate of QListWidget

两盒软妹~` 提交于 2019-12-25 18:48:12
问题 I'm painting a QPixmap inside the QItemDelegate of QListWidget. Each QListWidgetItem is of different dimensions. Inside the void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) function of QItemDelegate, I want to paint QPixmap with center Alignment inside the QListWidgetItem. option.rect() gives the geometry of the item with which I can calculate the center position and paint accordingly, but I want to know the better approach for this alignment.Can

QPainter::begin: Paint device returned engine == 0, type: 2

时光毁灭记忆、已成空白 提交于 2019-12-25 08:02:14
问题 I'm trying to print Qtablewidget but it just print a blank page and application output show QPrinter::metric: Invalid metric command QPainter::begin: Paint device returned engine == 0, type: 2 QWidget::render: Cannot render with an inactive painter print function void MainWindow::on_btPrint_clicked(){ QPrinter printer(QPrinter::HighResolution); QPrintDialog printer_dialog(&printer, this); if (printer_dialog.exec() == QDialog::Rejected) return; QPainter painter(&printer); ui->table_log->render

Qt - draw inside QScrollArea in a QDialog

假如想象 提交于 2019-12-25 04:24:20
问题 In Qt 5, I have a QDialog window on which I have drawn a circle as follows: void MyDialog::paintEvent(QPaintEvent *pe) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing,true); QPen pen(Qt::blue,2); painter.setPen(pen); QRect r=QRect(0,0,100,100); painter.drawEllipse(r); } If I draw a larger circle, for example by using QRect(0,0,500,500); , the circle being greater than the dialog window is clipped. So I dragged a QScrollArea onto the the dialog window and decide to draw

c++ 2d plotting tool for linux

倾然丶 夕夏残阳落幕 提交于 2019-12-25 00:29:39
问题 I am looking for a simple c++ 2d plotting tool for Linux (to be more honest "Cross-platform"). "koolplot" is nice but I think it's for windows only since its code includes graphics.h and windows.h. Someone suggested Qt's QPainter, but I cannot even use it to draw a single point. :'( So, if there is any help on other plotting tool or a decent tutorial on Qt's QPainter, I would be very grateful. Thanks. 回答1: Check out Qwt. It's worked well for all of my 2D applications, plus it's cross-platform