Qt Utilities 6.14.3
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
Loading...
Searching...
No Matches
QtUtilities::ButtonOverlay Class Reference

The ButtonOverlay class is used to display buttons on top of other widgets. More...

#include <buttonoverlay.h>

Inheritance diagram for QtUtilities::ButtonOverlay:
[legend]

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ButtonOverlay() [1/2]

QtUtilities::ButtonOverlay::ButtonOverlay ( QWidget * widget)
explicit

Constructs a button overlay for the specified widget.

Parameters
widgetSpecifies the widget to display the buttons on.
Remarks
This function enforces the "custom approach" mentioned in the class documentation and should therefore be avoided.

Definition at line 49 of file buttonoverlay.cpp.

◆ ButtonOverlay() [2/2]

QtUtilities::ButtonOverlay::ButtonOverlay ( QWidget * widget,
QLineEdit * lineEdit )
explicit

Constructs a button overlay for the specified widget.

Parameters
widgetSpecifies the widget to display the buttons on.
lineEditSpecifies 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.

◆ ~ButtonOverlay()

QtUtilities::ButtonOverlay::~ButtonOverlay ( )
virtual

Destroys the button overlay.

Definition at line 80 of file buttonoverlay.cpp.

Member Function Documentation

◆ addCustomAction()

void QtUtilities::ButtonOverlay::addCustomAction ( QAction * action)

Adds a custom action.

Definition at line 244 of file buttonoverlay.cpp.

◆ addCustomButton()

void QtUtilities::ButtonOverlay::addCustomButton ( QWidget * button)

Adds a custom button.

The button overlay takes ownership over the specified button.

Remarks
This function enforces the "custom approach" mentioned in the class documentation and should therefore be avoided.

Definition at line 209 of file buttonoverlay.cpp.

◆ buttonLayout()

QHBoxLayout * QtUtilities::ButtonOverlay::buttonLayout ( )

Returns the layout manager holding the buttons.

Remarks
This function enforces the "custom approach" mentioned in the class documentation and should therefore be avoided.

Definition at line 97 of file buttonoverlay.cpp.

◆ disableInfoButton()

void QtUtilities::ButtonOverlay::disableInfoButton ( )

Hides an info button if one is shown.

See also
ButtonOverlay::enableInfoButton()

Definition at line 185 of file buttonoverlay.cpp.

◆ enableInfoButton()

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.

See also
ButtonOverlay::disableInfoButton()

Definition at line 157 of file buttonoverlay.cpp.

◆ handleClearButtonClicked()

void QtUtilities::ButtonOverlay::handleClearButtonClicked ( )
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.

◆ handleCustomLayoutCreated()

void QtUtilities::ButtonOverlay::handleCustomLayoutCreated ( )
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.

◆ insertCustomAction()

void QtUtilities::ButtonOverlay::insertCustomAction ( int index,
QAction * action )

Inserts a custom action at the specified index.

Definition at line 256 of file buttonoverlay.cpp.

◆ insertCustomButton()

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.

Remarks
This function enforces the "custom approach" mentioned in the class documentation and should therefore be avoided.

Definition at line 223 of file buttonoverlay.cpp.

◆ isClearButtonEnabled()

bool QtUtilities::ButtonOverlay::isClearButtonEnabled ( ) const

Returns whether the clear button is enabled.

Definition at line 106 of file buttonoverlay.cpp.

◆ isCleared()

bool QtUtilities::ButtonOverlay::isCleared ( ) const
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.

◆ isInfoButtonEnabled()

bool QtUtilities::ButtonOverlay::isInfoButtonEnabled ( ) const

Returns whether the info button is enabled.

Definition at line 117 of file buttonoverlay.cpp.

◆ isUsingCustomLayout()

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.

◆ removeCustomAction()

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.

◆ removeCustomButton()

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.

◆ setClearButtonEnabled()

void QtUtilities::ButtonOverlay::setClearButtonEnabled ( bool enabled)

Sets whether the clear button is enabled.

Definition at line 125 of file buttonoverlay.cpp.

◆ updateClearButtonVisibility()

void QtUtilities::ButtonOverlay::updateClearButtonVisibility ( bool visible)
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.

Friends And Related Symbol Documentation

◆ ClearComboBox

friend class ClearComboBox
friend

Definition at line 27 of file buttonoverlay.h.

◆ ClearLineEdit

friend class ClearLineEdit
friend

Definition at line 30 of file buttonoverlay.h.

◆ ClearPlainTextEdit

friend class ClearPlainTextEdit
friend

Definition at line 29 of file buttonoverlay.h.

◆ ClearSpinBox

friend class ClearSpinBox
friend

Definition at line 28 of file buttonoverlay.h.


The documentation for this class was generated from the following files: