qpainter

How to make Qt widgets fade in or fade out?

随声附和 提交于 2019-11-30 03:04:18
I am trying to fade in and fade out a QLabel or for that matter any QWidget subclass. I have tried with QGraphicsEffect , but unfortunately it works well only on Windows and not on Mac. The only other solution which can work on both Mac & Windows seems to be having my own custom paintEvent where I set the opacity of QPainter and also define a Q_PROPERTY for "opacity" in my derived QLabel and change the opacity through QPropertyAnimation . I am pasting below the relevant code snippet for your reference. I still see an issue here - reusing the QLabel::paintEvent doesn't seem to be working, it

Render QWidget in paint() method of QWidgetDelegate for a QListView

好久不见. 提交于 2019-11-30 02:08:12
i'm having difficulties implementing custom widget rendering in a QListView . I currently have a QListView displaying my custom model called PlayQueue based on QAbstractListModel . This is working fine with simple text, but now I would like to display a custom widget for each element. So I subclassed a QStyledItemDelegate to implement the paint method like this: void QueueableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const { if (option.state & QStyle::State_Selected) painter->fillRect(option.rect, option.palette.highlight()); QWidget

Using QPainter over OpenGL in QGLWidget when using shaders

让人想犯罪 __ 提交于 2019-11-29 18:22:53
问题 Many of you Qt (4.6 specifically) users will be familiar with the Overpainting example supplied in the OpenGL tutorials, I'm trying to do something very similar but using shaders for the pure OpenGL data, instead of the old fixed-function pipeline. // Set background and state. makeCurrent(); qglClearColor( bgColour_ ); glEnable( GL_DEPTH_TEST ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); if ( smoothLines_ ) { glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

Qt - circles for collision detection

孤者浪人 提交于 2019-11-29 14:52:01
I've been working on a physics simulation with circles in Qt. Thus far the easiest way to define circles I found is to make a QRect object and then draw the ellipse with that rectangle as a "blueprint". Now I've just got the problem that it paints a circle but the hit box for the hit detection is still a square, which looks rather awkward. I've not been able to find a solution for it thus far and hope to find some help here. QRectF Ball::boundingRect() const { return QRect(0,0,20,20); } void Ball::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QRectF rec =

How to rotate a QPushButton?

主宰稳场 提交于 2019-11-29 10:40:57
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, like signals do, but it hasn't. All I can seem to get from this event is a QRect or QRegion. How can I

How to make Qt widgets fade in or fade out?

流过昼夜 提交于 2019-11-29 00:45:46
问题 I am trying to fade in and fade out a QLabel or for that matter any QWidget subclass. I have tried with QGraphicsEffect , but unfortunately it works well only on Windows and not on Mac. The only other solution which can work on both Mac & Windows seems to be having my own custom paintEvent where I set the opacity of QPainter and also define a Q_PROPERTY for "opacity" in my derived QLabel and change the opacity through QPropertyAnimation . I am pasting below the relevant code snippet for your

Qt drawing a filled rounded rectangle with border

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 23:11:07
I want to draw a rectangle with rounded corners (border radius same for all 4 corners) with a specific color filling the entire rectangle, and a separate border color (say border is 1 px wide). From my observation, Qt provides three methods - fillRect and drawRect and drawRoundedRect . I have tried them, they don't work like I want to. There is no method like fillRoundedRect . Which means that I can draw a rounded rectangle but it won't be filled with the color I want. How do I do it? And also, I read that due to some aliasing problems, the corners are often rendered as unequal. How do I set

Render QWidget in paint() method of QWidgetDelegate for a QListView

戏子无情 提交于 2019-11-28 23:03:53
问题 i'm having difficulties implementing custom widget rendering in a QListView . I currently have a QListView displaying my custom model called PlayQueue based on QAbstractListModel . This is working fine with simple text, but now I would like to display a custom widget for each element. So I subclassed a QStyledItemDelegate to implement the paint method like this: void QueueableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const { if (option

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

牧云@^-^@ 提交于 2019-11-28 14:15:21
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); // Problem: QPainter::begin: Paint device returned engine == 0, type: 1 const QPixmap pm(QPixmap:

Qt : Smooth a circular mask. Remove Jagged edges

情到浓时终转凉″ 提交于 2019-11-28 12:55:16
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. 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 support anti-aliasing, each pixel is either fully opaque or fully transparent. This results in jagged edges. The