Skip to content
QtWS25 Last Chance
  • QGraphicsScene Composition modes

    Solved General and Desktop qt c++ compositionmode qpainter
    3
    0 Votes
    3 Posts
    164 Views
    S
    @Pl45m4 Yeah forgot to set opacity to something else than 1, that solved it...
  • 0 Votes
    4 Posts
    318 Views
    G
    For the historical record, I finally got it working. My code: ` QRect screenGeometry = QGuiApplication::primaryScreen( )->geometry( ); int x13; int x23; int y13; int y23; if( screenGeometry.width( ) < width( )) { x13 = m_image->getScrollX( ) + screenGeometry.width( ) / 3.0; x23 = m_image->getScrollX( ) + 2 * screenGeometry.width( ) / 3.0; } else { x13 = m_image->getScrollX( ) + width( ) / 3.0; x23 = m_image->getScrollX( ) + 2 * width( ) / 3.0; } if( screenGeometry.height( ) < height( )) { y13 = m_image->getScrollY( ) + screenGeometry.height( ) / 3.0; y23 = m_image->getScrollY( ) + 2 * screenGeometry.height( ) / 3.0; } else { y13 = m_image->getScrollY( ) + height( ) / 3.0; y23 = m_image->getScrollY( ) + 2 * height( ) / 3.0; } QPainter painter( this ); painter.setPen( QPen( Qt::red, 4, Qt::SolidLine, Qt::FlatCap )); painter.drawLine( 0, y13, width( ), y13 ); painter.drawLine( 0, y23, width( ), y23 ); painter.drawLine( x13, 0, x13, height( )); painter.drawLine( x23, 0, x23, height( )); } `
  • Drawing composed widget

    Solved General and Desktop qpainter qwidget qpainterpath
    5
    0 Votes
    5 Posts
    443 Views
    Pl45m4P
    Solved. For further readers: I've added a check to the child widget whether a user interaction happens within its drawn borders (a closed QPainterPath). If so, I consume the event and continue from there, if not, I ignore the event and pass it to the parent widget, i.e. the actual MyWidget, so that the overlaying child widget has some transparency for my defined events (some key and mouse interaction). Pretty easy if I think about it now. The idea of having some kind of a donut shaped widget (yellow part in my sketch), which does not occupy the center of its parent widget was stuck in my head way too long :))
  • QPainter does not work

    Unsolved General and Desktop qpainter qline qimage qwidget qpaintevent
    18
    0 Votes
    18 Posts
    2k Views
    C
    @Joe-von-Habsburg My example recast with a changing background: // widget.h #ifndef WIDGET_H #define WIDGET_H #include <QWidget> class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr); ~Widget(); // QWidget interface protected: void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void paintEvent(QPaintEvent *event); private slots: void setBackground(); private: QImage mBackground; QPointF mFrom; QPointF mTo; }; #endif // WIDGET_H // widget.cpp #include "widget.h" #include <QPaintEvent> #include <QPainter> #include <QLinearGradient> #include <QRandomGenerator> #include <QTimer> #include <QDebug> Widget::Widget(QWidget *parent) : QWidget(parent) , mBackground(500, 500, QImage::Format_RGB32) { setBackground(); QTimer *t = new QTimer(this); connect(t, &QTimer::timeout, this, &Widget::setBackground); t->start(1000); } Widget::~Widget() { } void Widget::mousePressEvent(QMouseEvent *event) { mFrom = event->position(); mTo = mFrom; } void Widget::mouseReleaseEvent(QMouseEvent *event) { mTo = event->position(); update(); } void Widget::paintEvent(QPaintEvent *event) { QPainter p(this); p.drawImage(event->rect(), mBackground); if (mFrom != mTo) { QPen pen(Qt::red); pen.setWidth(3); p.setPen(pen); p.drawLine(mFrom, mTo); } p.end(); } void Widget::setBackground() { QPainter p(&mBackground); const QRectF rectf(mBackground.rect()); QLinearGradient grad(rectf.topLeft(), rectf.bottomRight()); grad.setColorAt(0, QColor::fromRgb(QRandomGenerator::global()->generate())); grad.setColorAt(1, QColor::fromRgb(QRandomGenerator::global()->generate())); p.fillRect(mBackground.rect(), QBrush(grad)); p.end(); update(); }
  • 0 Votes
    1 Posts
    226 Views
    No one has replied
  • 0 Votes
    5 Posts
    854 Views
    S
    @JonB thanks for googling :) . I have seen some more example. In case of GraphicsView fill transparent on scene did not help. I am pretty sure there is some way to do it, need to google more
  • Incorrect Bounding Rect?

    Unsolved General and Desktop qfontmetrics qpainter
    3
    0 Votes
    3 Posts
    484 Views
    CJhaC
    @Pl45m4 In this function I am painting on axis->labelPix which is a QPixmap. The axis->labelPix is then put in its correct position using QPainter in the paintEvent() of PlotWidget.
  • add qpainterpath into a QProgressBar

    Unsolved General and Desktop qprogressbar qpainter qpainterpath
    3
    0 Votes
    3 Posts
    564 Views
    S
    thank you for the direction.
  • QPainter takes much more time to draw thicker curves?

    Unsolved General and Desktop qpainter
    1
    0 Votes
    1 Posts
    324 Views
    No one has replied
  • How to redraw a button ??

    Solved General and Desktop qt5.5 qt6.2 qpushbutton qpainter
    6
    0 Votes
    6 Posts
    1k Views
    Chris KawaC
    The constructors are still wrong. Should be QSliderButton::QSliderButton(QWidget* parent) : QWidget(parent) {} and the empty one is just redundant. You don't need it at all. Better yet don't manually implement any constructors, just do class QSliderButton : public QWidget { Q_OBJECT public: using QWidget::QWidget; ... The using statement will inherit all the constructors from the base class so you don't have to implement any.
  • 0 Votes
    3 Posts
    854 Views
    Guy GizmoG
    I'm afraid that doesn't help for my use case, since I need the images to appear as clear and clean as possible when being scaled down.
  • Is stroke the text (Circle text )

    Solved General and Desktop qt5.11 qpainter
    4
    0 Votes
    4 Posts
    803 Views
    M
    @timob256 said in Is stroke the text (Circle text ): cannot align the bypass line with the inner line Sorry, i don't understand. If you want the background to be green, add a fillPath before stroke path: painter.fillPath(path,Qt::green); painter.strokePath(path,pen);
  • 0 Votes
    2 Posts
    590 Views
    Christian EhrlicherC
    Simply two QPainter::drawArc() calls with a different color.
  • 0 Votes
    11 Posts
    1k Views
    SGaistS
    @Vijay-R-Gawade said in Qt app freeze when remove usb drive while qpainter is drwaing: @SGaist Timer is used to add some delay to Update Progress bar on UI by one step when each record from DB is drawn. That's a fishy procedure to update your progress bar.
  • 0 Votes
    10 Posts
    1k Views
    SGaistS
    One of the issue here is that the conversion must be done each time the draw method is called. If you know that your images will not change or not much then you should do the conversion upfront so that the painting can be optimized.
  • memory leak width QPainter/QPrinter

    Unsolved General and Desktop qpainter qprinter memory leak
    18
    0 Votes
    18 Posts
    3k Views
    AaronCA
    @Christian-Ehrlicher Thanks for tracking that down. Hope Qt gets it fixed soon.
  • 0 Votes
    3 Posts
    4k Views
    Fitndex-developerF
    Thank you so much nagesh.
  • Web enabling a desktop app.

    Unsolved QtWebEngine web app qpainter qgraphicsscene
    4
    0 Votes
    4 Posts
    858 Views
    JonBJ
    @TenG Be aware that not all of Qt modules are supported in WASM. Before anything, check the list at https://doc.qt.io/qt-5/wasm.html#supported-qt-modules against what is in your app. For example, it doesn't do databases, you can't access the local file system, and so on. Also I noticed this time that it requires a Qt static build, but maybe you have to have that for iOS anyway, I don't know. If it works for you it's a really simple solution compared to rewriting anything. Just check out the gotchas.
  • 0 Votes
    9 Posts
    1k Views
    SGaistS
    Thanks for the code ! You can use the Q_OS_XXX macros to ifdef your code.
  • 0 Votes
    2 Posts
    433 Views
    Kent-DorfmanK
    so write a test program, meter the performance of canvas writes vs out-of-bounds writes, and report back.