ClearPlainTextEdit: buttons are no longer displayed over the scroll bar
This commit is contained in:
parent
152df3a2f6
commit
2a9d4cb353
|
@ -1,6 +1,11 @@
|
|||
#include "./clearplaintextedit.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <functional>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Widgets {
|
||||
|
||||
|
@ -14,12 +19,15 @@ namespace Widgets {
|
|||
*/
|
||||
ClearPlainTextEdit::ClearPlainTextEdit(QWidget *parent) :
|
||||
QPlainTextEdit(parent),
|
||||
ButtonOverlay(this)
|
||||
ButtonOverlay(viewport())
|
||||
{
|
||||
// set alignment to show buttons in the bottom right corner
|
||||
ButtonOverlay::buttonLayout()->setAlignment(Qt::AlignBottom | Qt::AlignRight);
|
||||
ButtonOverlay::setClearButtonEnabled(true);
|
||||
connect(document(), &QTextDocument::contentsChanged, this, &ClearPlainTextEdit::handleTextChanged);
|
||||
// ensure button layout is realigned when scrolling
|
||||
connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, &ClearPlainTextEdit::handleScroll);
|
||||
connect(this->verticalScrollBar(), &QScrollBar::rangeChanged, this, &ClearPlainTextEdit::handleScroll);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -44,6 +52,11 @@ void ClearPlainTextEdit::handleClearButtonClicked()
|
|||
cursor.removeSelectedText();
|
||||
}
|
||||
|
||||
void ClearPlainTextEdit::handleScroll()
|
||||
{
|
||||
buttonLayout()->update();
|
||||
}
|
||||
|
||||
bool ClearPlainTextEdit::isCleared() const
|
||||
{
|
||||
return document()->isEmpty();
|
||||
|
|
|
@ -18,6 +18,7 @@ public:
|
|||
private Q_SLOTS:
|
||||
void handleTextChanged();
|
||||
void handleClearButtonClicked();
|
||||
void handleScroll();
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue