Qt Utilities 6.14.3
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
|
The ButtonOverlay class is used to display buttons on top of other widgets. More...
#include <buttonoverlay.h>
Public Member Functions | |
ButtonOverlay (QWidget *widget) | |
Constructs a button overlay for the specified widget. | |
ButtonOverlay (QWidget *widget, QLineEdit *lineEdit) | |
Constructs a button overlay for the specified widget. | |
virtual | ~ButtonOverlay () |
Destroys the button overlay. | |
bool | isUsingCustomLayout () const |
Returns whether the "custom approach" mentioned in the class documentation is used. | |
QHBoxLayout * | buttonLayout () |
Returns the layout manager holding the buttons. | |
bool | isClearButtonEnabled () const |
Returns whether the clear button is enabled. | |
void | setClearButtonEnabled (bool enabled) |
Sets whether the clear button is enabled. | |
bool | isInfoButtonEnabled () const |
Returns whether the info button is enabled. | |
void | enableInfoButton (const QPixmap &pixmap, const QString &infoText) |
Shows an info button with the specified pixmap and infoText. | |
void | disableInfoButton () |
Hides an info button if one is shown. | |
void | addCustomButton (QWidget *button) |
Adds a custom button. | |
void | insertCustomButton (int index, QWidget *button) |
Inserts a custom button at the specified index. | |
void | removeCustomButton (QWidget *button) |
Removes the specified custom button; does nothing if button has not been added. | |
void | addCustomAction (QAction *action) |
Adds a custom action. | |
void | insertCustomAction (int index, QAction *action) |
Inserts a custom action at the specified index. | |
void | removeCustomAction (QAction *action) |
Removes the specified custom action; does nothing if action has not been added. | |
virtual bool | isCleared () const |
Returns whether the related widget is cleared. | |
Protected Member Functions | |
void | updateClearButtonVisibility (bool visible) |
Updates the visibility of the clear button. | |
virtual void | handleClearButtonClicked () |
Clears the related widget. | |
virtual void | handleCustomLayoutCreated () |
Applies additional handling when the button layout has been created. | |
Friends | |
class | ClearComboBox |
class | ClearSpinBox |
class | ClearPlainTextEdit |
class | ClearLineEdit |
The ButtonOverlay class is used to display buttons on top of other widgets.
This class had been created before QLineEdit's functions setClearButtonEnabled() and addAction() have been available. (These functions have been available only since Qt 5.2.)
The downside of the "custom approach" compared to QLineEdit's own functions is that the buttons are shown over the text as the text margins are not updated accordingly. Hence the ButtonOverlay class has been updated to use QLineEdit's functions internally when the specified widget is QLineEdit-based and its QLineEdit has been passed to the constructor. However, when using any functions which can not be implemented using QLineEdit's own functions, the ButtonOverlay has to fallback to its "custom approach". All functions which cause this have a remark in their documentation.
When QLineEdit's functions can not be used, the ButtonOverlay class creates a new layout manager and sets it to the widget specified when constructing an instance. Thus this widget must not already have a layout manager.
The class is used to implement widget customization like ClearLineEidt and ClearComboBox and most of the times it makes sense to use these widgets instead of using ButtonOverlay directly.
Definition at line 25 of file buttonoverlay.h.
|
explicit |
Constructs a button overlay for the specified widget.
widget | Specifies the widget to display the buttons on. |
Definition at line 49 of file buttonoverlay.cpp.
|
explicit |
Constructs a button overlay for the specified widget.
widget | Specifies the widget to display the buttons on. |
lineEdit | Specifies the line edit used by widget to use the QLineEdit's functions for adding actions instead of a custom layout. |
Definition at line 65 of file buttonoverlay.cpp.
|
virtual |
Destroys the button overlay.
Definition at line 80 of file buttonoverlay.cpp.
void QtUtilities::ButtonOverlay::addCustomAction | ( | QAction * | action | ) |
Adds a custom action.
Definition at line 244 of file buttonoverlay.cpp.
void QtUtilities::ButtonOverlay::addCustomButton | ( | QWidget * | button | ) |
Adds a custom button.
The button overlay takes ownership over the specified button.
Definition at line 209 of file buttonoverlay.cpp.
QHBoxLayout * QtUtilities::ButtonOverlay::buttonLayout | ( | ) |
Returns the layout manager holding the buttons.
Definition at line 97 of file buttonoverlay.cpp.
void QtUtilities::ButtonOverlay::disableInfoButton | ( | ) |
Hides an info button if one is shown.
Definition at line 185 of file buttonoverlay.cpp.
void QtUtilities::ButtonOverlay::enableInfoButton | ( | const QPixmap & | pixmap, |
const QString & | infoText ) |
Shows an info button with the specified pixmap and infoText.
If there is already an info button enabled, it gets replaced with the new button.
Definition at line 157 of file buttonoverlay.cpp.
|
protectedvirtual |
Clears the related widget.
This function is meant to be implemented when subclassing to support the clear button.
Definition at line 295 of file buttonoverlay.cpp.
|
protectedvirtual |
Applies additional handling when the button layout has been created.
This function is meant to be implemented when subclassing when additional handling is required.
Definition at line 305 of file buttonoverlay.cpp.
void QtUtilities::ButtonOverlay::insertCustomAction | ( | int | index, |
QAction * | action ) |
Inserts a custom action at the specified index.
Definition at line 256 of file buttonoverlay.cpp.
void QtUtilities::ButtonOverlay::insertCustomButton | ( | int | index, |
QWidget * | button ) |
Inserts a custom button at the specified index.
The button overlay takes ownership over the specified button.
Definition at line 223 of file buttonoverlay.cpp.
bool QtUtilities::ButtonOverlay::isClearButtonEnabled | ( | ) | const |
Returns whether the clear button is enabled.
Definition at line 106 of file buttonoverlay.cpp.
|
virtual |
Returns whether the related widget is cleared.
This method is meant to be implemented when subclassing.
Reimplemented in QtUtilities::ClearComboBox, QtUtilities::ClearLineEdit, QtUtilities::ClearPlainTextEdit, and QtUtilities::ClearSpinBox.
Definition at line 377 of file buttonoverlay.cpp.
bool QtUtilities::ButtonOverlay::isInfoButtonEnabled | ( | ) | const |
Returns whether the info button is enabled.
Definition at line 117 of file buttonoverlay.cpp.
bool QtUtilities::ButtonOverlay::isUsingCustomLayout | ( | ) | const |
Returns whether the "custom approach" mentioned in the class documentation is used.
Definition at line 87 of file buttonoverlay.cpp.
void QtUtilities::ButtonOverlay::removeCustomAction | ( | QAction * | action | ) |
Removes the specified custom action; does nothing if action has not been added.
Definition at line 269 of file buttonoverlay.cpp.
void QtUtilities::ButtonOverlay::removeCustomButton | ( | QWidget * | button | ) |
Removes the specified custom button; does nothing if button has not been added.
The ownership of widget remains the same as when it was added.
Definition at line 234 of file buttonoverlay.cpp.
void QtUtilities::ButtonOverlay::setClearButtonEnabled | ( | bool | enabled | ) |
Sets whether the clear button is enabled.
Definition at line 125 of file buttonoverlay.cpp.
|
protected |
Updates the visibility of the clear button.
This function is meant to be called when subclassing.
Definition at line 283 of file buttonoverlay.cpp.
|
friend |
Definition at line 27 of file buttonoverlay.h.
|
friend |
Definition at line 30 of file buttonoverlay.h.
|
friend |
Definition at line 29 of file buttonoverlay.h.
|
friend |
Definition at line 28 of file buttonoverlay.h.