How can I make paintEvent triggered only when update is called? Ask Question. Asked 8 years, 4 months ago. Active 8 years, 4 months ago.
Viewed 3k times. Improve this question. Kuba hasn't forgotten Monica May May 1 1 1 silver badge 6 6 bronze badges. I still think that you're architecting it horribly wrong if you really think you need to do what you think you need to do.
Please edit your question and provide some background as to exactly what you're doing and why this weird requirement has come up. Add a comment. Active Oldest Votes. The idiomatic way of handling widget updates is as follows: The source of data that the widget uses is updated. Improve this answer.
Community Bot 1 1 1 silver badge. Kuba hasn't forgotten Monica Kuba hasn't forgotten Monica I know a little about the mechanism of update.
See also paintGL and resizeGL. Returns true if the widget and OpenGL resources, like the context, have been successfully initialized. Note that the return value is always false until the widget is shown.
Prepares for rendering OpenGL content for this widget by making the corresponding context current and binding the framebuffer object in that context. It is not necessary to call this function in most cases, because it is called automatically before invoking paintGL. See also context , paintGL , and doneCurrent. Calling QWidget::update will lead to sending a paint event e , and thus invoking this function.
NB this is asynchronous and will happen at some point after returning from update. The widget's top-level window will then composite the framebuffer's texture with the rest of the window. This virtual function is called whenever the widget needs to be painted. Before invoking this function, the context and the framebuffer are bound, and the viewport is set up by a call to glViewport. No other state is set and no clearing or drawing is performed by the framework.
See also initializeGL and resizeGL. Handles resize events that are passed in the e event parameter. Calls the virtual function resizeGL. Note: Avoid overriding this function in derived classes. Otherwise the underlying framebuffer object and related resources will not get resized properly and will lead to incorrect rendering. This virtual function is called whenever the widget has been resized. The new size is passed in w and h. Additionally, the framebuffer is also bound.
See also initializeGL and paintGL. When the format is not explicitly set via this function, the format returned by QSurfaceFormat::defaultFormat will be used. This means that when having multiple OpenGL widgets, individual calls to this function can be replaced by one single call to QSurfaceFormat::setDefaultFormat before creating the first widget.
Note: Requesting an alpha buffer via this function will not lead to the desired results when the intention is to make other widgets beneath visible. Keep in mind however that this breaks the stacking order, so it will no longer be possible to have other widgets on top of the QOpenGLWidget. This can be achieved by calling this function. Note: This function has no effect if called after the widget has already been shown and thus it performed initialization.
Returns the active internal texture format if the widget has already initialized, the requested format if one was set but the widget has not yet been made visible, or nullptr if setTextureFormat was not called and the widget has not yet been made visible.
Documentation contributions included herein are the copyrights of their respective owners. Qt and respective logos are trademarks of The Qt Company Ltd. All other trademarks are property of their respective owners. Gets called whenever the widget needs to be updated. Gets called whenever the widget has been resized and also when it is shown for the first time because all newly created widgets get a resize event automatically. Gets called once before the first time resizeGL or paintGL is called.
NoPartialUpdate can have some performance benefits on certain hardware architectures common in the mobile and embedded space when a framebuffer object is used as the rendering target. The framebuffer objects color buffer and ancillary buffers are not invalidated between frames. The use of widget style sheets is described in more detail in the Qt Style Sheets document.
Since Qt 4. Custom widgets can be written to take advantage of this feature by updating irregular regions to create non-rectangular child widgets , or painting with colors that have less than full alpha component. The following diagram shows how attributes and properties of a custom widget can be fine-tuned to achieve different effects.
In the above diagram, a semi-transparent rectangular child widget with an area removed is constructed and added to a parent widget a QLabel showing a pixmap. Then, different properties and widget attributes are set to achieve different effects:. To rapidly update custom widgets with simple background colors, such as real-time plotting or graphing widgets, it is better to define a suitable background color using setBackgroundRole with the QPalette::Window role , set the autoFillBackground property, and only implement the necessary drawing functionality in the widget's paintEvent.
To rapidly update custom widgets that constantly paint over their entire areas with opaque content, e. Depending on your requirements, you should choose either one of them. This can lead to some unexpected results if the parent widget is decorated in a non-standard way, as shown in the diagram below.
The scope for customizing the painting behavior of standard Qt widgets, without resorting to subclassing, is slightly less than that possible for custom widgets. Usually, the desired appearance of a standard widget can be achieved by setting its autoFillBackground property. Introduced in Qt 4. They do not have a native window handle associated with them.
This feature significantly speeds up widget painting, resizing, and removes flicker. Should you require the old behavior with native windows, you can choose one of the following options:.
This enum describes how to render the widget when calling QWidget::render. It stores an OR combination of RenderFlag values. Setting this property to true announces to the system that this widget may be able to accept drop events.
The accessible description of a widget should convey what a widget does. While the accessibleName should be a short and concise string e. Save , the description should give more context, such as Saves the current document.
By default, this property contains an empty string and Qt falls back to using the tool tip to provide this information. This is the primary name by which assistive technology such as screen readers announce this widget. For most widgets setting this property is not required.
For example for QPushButton the button's text will be used. It is important to set this property when the widget does not provide any text. For example a button that only contains an icon needs to set this property to work with screen readers.
The name should be short and equivalent to the visual information conveyed by the widget. If enabled, this property will cause Qt to fill the background of the widget before invoking the paint event.
The color used is defined by the QPalette::Window color role from the widget's palette. This property cannot be turned off i. Warning: Use this property with caution in conjunction with Qt Style Sheets. When a widget has a style sheet with a valid background or a border-image, this property is automatically disabled. The base size is used to calculate a proper widget size if the widget defines sizeIncrement.
By default, for a newly-created widget, this property contains a size with zero width and height. By default, for a widget with no children, this property contains a rectangle with zero width and height located at the origin. See also childrenRegion and geometry. See also childrenRect , geometry , and mask. The mouse cursor will assume this shape when it's over this widget.
See the list of predefined cursor objects for a range of useful shapes. By default, this property contains a cursor with the Qt::ArrowCursor shape. Some underlying window implementations will reset the cursor if it leaves a widget even if the mouse is grabbed. If you want to have a cursor set for all widgets, even when outside the window, consider QGuiApplication::setOverrideCursor.
In general an enabled widget handles keyboard and mouse events; a disabled widget does not. An exception is made with QAbstractButton. Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out. If your widget needs to know when it becomes enabled or disabled, you can use the changeEvent with type QEvent::EnabledChange.
Disabling a widget implicitly disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled. It it not possible to explicitly enable a child widget which is not a window while its parent widget remains disabled. Note: Obtaining the value of this property for a widget is effectively equivalent to checking whether QApplication::focusWidget refers to the widget. The policy is Qt::TabFocus if the widget accepts keyboard focus by tabbing, Qt::ClickFocus if the widget accepts focus by clicking, Qt::StrongFocus if it accepts both, and Qt::NoFocus the default if it does not accept focus at all.
You must enable keyboard focus for a widget if it processes keyboard events. This is normally done from the widget's constructor. This property describes the widget's requested font.
The font is used by the widget's style when rendering standard components, and is available as a means to ensure that custom widgets can maintain consistency with the native platform's look and feel. It's common that different platforms, or different styles, define different fonts for an application. When you assign a new font to a widget, the properties from this font are combined with the widget's default font to form the widget's final font.
You can call fontInfo to get a copy of the widget's final font. The final font is also used to initialize QPainter 's font. The default depends on the system environment. There may also be special font defaults for certain types of widgets.
You can also define default fonts for widgets yourself by passing a custom font and the name of a widget to QApplication::setFont. Finally, the font is matched against Qt's font database to find the best match. QWidget propagates explicit font properties from parent to child. If you change a specific property on a font and assign that font to a widget, that property will propagate to all the widget's children, overriding any system defaults for that property.
The current style, which is used to render the content of all standard Qt widgets, is free to choose to use the widget font, or in some cases, to ignore it partially, or completely. In particular, certain styles like GTK style, Mac style, and Windows Vista style, apply special modifications to the widget font to match the platform's native look and feel.
Because of this, assigning properties to a widget's font is not guaranteed to change the appearance of the widget.
Instead, you may choose to apply a styleSheet. Note: If Qt Style Sheets are used on the same widget as setFont , style sheets will take precedence if the settings conflict. See also fontInfo and fontMetrics. See the Window Geometry documentation for an overview of geometry issues with windows. By default, this property contains a value that depends on the user's platform and screen geometry.
See also geometry , x , y , and pos. A widget in full screen mode occupies the whole screen area and does not display window decorations, such as a title bar.
See also windowState , minimized , and maximized. This property holds the geometry of the widget relative to its parent and excluding the window frame.
If the widget is not currently visible, it is guaranteed to receive appropriate events before it is shown. The size component is adjusted if it lies outside the range defined by minimumSize and maximumSize.
Warning: Calling setGeometry inside resizeEvent or moveEvent can lead to infinite recursion. See also frameGeometry , rect , move , resize , moveEvent , resizeEvent , minimumSize , and maximumSize. Note: Do not use this function to find the height of a screen on a multiple screen desktop. Read this note for details. See also geometry , width , and size. This is only relevant for input widgets. It is used by the input method to retrieve hints as to how the input method should operate.
For example, if the Qt::ImhFormattedNumbersOnly flag is set, the input method may change its visual components to reflect that only numbers can be entered. Warning: Some widgets require certain flags in order to work as intended.
Note: The flags are only hints, so the particular input method implementation is free to ignore them. If you want to be sure that a certain type of characters are entered, you should also set a QValidator on the widget.
The active window is the window that contains the widget that has keyboard focus The window may still have focus if it has no widgets or none of its widgets accepts keyboard focus. When popup windows are visible, this property is true for both the active window and for the popup. See also activateWindow and QApplication::activeWindow. When the layout direction is set on a widget, it will propagate to the widget's children, but not to a child that is a window and not to a child for which setLayoutDirection has been explicitly called.
Also, child widgets added after setLayoutDirection has been called for the parent do not inherit the parent's layout direction. See also QApplication::layoutDirection. As long as no special locale has been set, this is either the parent's locale or if this widget is a top level widget , the default locale. Note: Due to limitations on some window systems, this does not always report the expected results e.
This is expected to improve as window manager protocols evolve. See also windowState , showMaximized , visible , show , hide , showNormal , and minimized. This property corresponds to the height held by the maximumSize property. See also maximumSize and maximumWidth. By default, this property contains a size in which both width and height have values of See also maximumWidth , maximumHeight , minimumSize , and sizeIncrement.
This property corresponds to the width held by the maximumSize property. See also maximumSize and maximumHeight. See also showMinimized , visible , show , hide , showNormal , and maximized. This property corresponds to the height held by the minimumSize property. See also minimumSize and minimumWidth. The widget cannot be resized to a smaller size than the minimum widget size. The widget's size is forced to the minimum size if the current size is smaller. The minimum size set by this function will override the minimum size defined by QLayout.
In order to unset the minimum size, use a value of QSize 0, 0. See also minimumWidth , minimumHeight , maximumSize , and sizeIncrement. The default implementation of minimumSizeHint returns an invalid size if there is no layout for this widget, and returns the layout's minimum size otherwise. Most built-in widgets reimplement minimumSizeHint.
QLayout will never resize a widget to a size smaller than the minimum size hint unless minimumSize is set or the size policy is set to QSizePolicy::Ignore. If minimumSize is set, the minimum size hint will be ignored.
This property corresponds to the width held by the minimumSize property. See also minimumSize and minimumHeight. This property only makes sense for windows. A modal widget prevents widgets in all other windows from getting any input.
See also isWindow , windowModality , and QDialog. If mouse tracking is disabled the default , the widget only receives mouse move events when at least one mouse button is pressed while the mouse is being moved. If mouse tracking is enabled, the widget receives mouse move events even if no buttons are pressed. This property holds the geometry of the widget as it will appear when shown as a normal not maximized or full screen top-level widget.
This property describes the widget's palette. The palette is used by the widget's style when rendering standard components, and is available as a means to ensure that custom widgets can maintain consistency with the native platform's look and feel. It's common that different platforms, or different styles, have different palettes. When you assign a new palette to a widget, the color roles from this palette are combined with the widget's default palette to form the widget's final palette.
The palette entry for the widget's background role is used to fill the widget's background see QWidget::autoFillBackground , and the foreground role initializes QPainter 's pen. There may also be special palette defaults for certain types of widgets e. You can also define default palettes for widgets yourself by passing a custom palette and the name of a widget to QApplication::setPalette. Finally, the style always has the option of polishing the palette as it's assigned see QStyle::polish.
QWidget propagates explicit palette roles from parent to child. If you assign a brush or color to a specific role on a palette and assign that palette to a widget, that role will propagate to all the widget's children, overriding any system defaults for that role.
The current style, which is used to render the content of all standard Qt widgets, is free to choose colors and brushes from the widget palette, or in some cases, to ignore the palette partially, or completely. In particular, certain styles like GTK style, Mac style, and Windows Vista style, depend on third party APIs to render the content of widgets, and these styles typically do not follow the palette.
Because of this, assigning roles to a widget's palette is not guaranteed to change the appearance of the widget. Warning: Do not use this function in conjunction with Qt Style Sheets. When using style sheets, the palette of a widget can be customized using the "color", "background-color", "selection-color", "selection-background-color" and "alternate-background-color".
If the widget is a window, the position is that of the widget on the desktop, including its frame. When changing the position, the widget, if visible, receives a move event moveEvent immediately. If the widget is not currently visible, it is guaranteed to receive an event before it is shown. Warning: Calling move or setGeometry inside moveEvent can lead to infinite recursion. See also frameGeometry , size , x , and y. The rect property equals QRect 0, 0, width , height.
If the widget is visible when it is being resized, it receives a resize event resizeEvent immediately. The size is adjusted if it lies outside the range defined by minimumSize and maximumSize. Warning: Calling resize or setGeometry inside resizeEvent can lead to infinite recursion. Note: Setting the size to QSize 0, 0 will cause the widget to not appear on screen. This also applies to windows. See also pos , geometry , minimumSize , maximumSize , resizeEvent , and adjustSize.
The default implementation of sizeHint returns an invalid size if there is no layout for this widget, and returns the layout's preferred size otherwise. When the user resizes the window, the size will move in steps of sizeIncrement. Preferred widget sizes are for non-negative integers i and j :. Warning: The size increment has no effect under Windows, and may be disregarded by the window manager on X See also size , minimumSize , and maximumSize. If there is a QLayout that manages this widget's children, the size policy specified by that layout is used.
If there is no such QLayout , the result of this function is used. Button-like widgets set the size policy to specify that they may stretch horizontally, but are fixed vertically. QToolButton 's are normally square, so they allow growth in both directions. Widgets that can provide scroll bars usually subclasses of QScrollArea tend to specify that they can use additional space, and that they can make do with less than sizeHint.
See also toolTip and whatsThis. The style sheet contains a textual description of customizations to the widget's style, as described in the Qt Style Sheets document. Warning: Qt style sheets are currently not supported for custom QStyle subclasses. We plan to address this in some future release. If tablet tracking is disabled the default , the widget only receives tablet move events when the stylus is in contact with the tablet, or at least one stylus button is pressed, while the stylus is being moved.
If tablet tracking is enabled, the widget receives tablet move events even while hovering in proximity. This is useful for monitoring position as well as the auxiliary properties such as rotation and tilt, and providing feedback in the UI. Note that by default tooltips are only shown for widgets that are children of the active window.
If you want to control a tooltip's behavior, you can intercept the event function and catch the QEvent::ToolTip event e. Specifies how long time the tooltip will be displayed, in milliseconds. If the value is -1 default the duration is calculated depending on the length of the tooltip. An updates enabled widget receives paint events and has a system background; a disabled widget does not. This also implies that calling update and repaint has no effect if updates are disabled.
In Qt, widgets normally do not generate screen flicker, but on X11 the server might erase regions on the screen when widgets get hidden before they can be replaced by other widgets. Disabling updates solves this. Enabling a widget enables all child widgets except top-level widgets or those that have been explicitly disabled. Re-enabling updates implicitly calls update on the widget. Calling setVisible true or show sets the widget to visible status if all its parent widgets up to the window are visible.
If an ancestor is not visible, the widget won't become visible until all its ancestors are shown. If its size or position has changed, Qt guarantees that a widget gets move and resize events just before it is shown. If the widget has not been resized yet, Qt will adjust the widget's size to a useful default using adjustSize. Calling setVisible false or hide hides a widget explicitly. An explicitly hidden widget will never become visible, even if all its ancestors become visible, unless you show it.
A widget receives show and hide events when its visibility status changes. Between a hide and a show event, there is no need to waste CPU cycles preparing or displaying information to the user. I think this doesn't just affect the paintEvent but other events as well. I'm also occasionally updating some other widgets which sometimes also stops when this error occurs. That's most likely due to the way update prevents multiple fast repaints. VRonin thanks, it works well! VRonin said in paintEvent not called after call to update :.
Where can I find this in documentation?
0コメント