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 "./clearplaintextedit.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QScrollBar>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace Widgets {
|
namespace Widgets {
|
||||||
|
|
||||||
|
@ -14,12 +19,15 @@ namespace Widgets {
|
||||||
*/
|
*/
|
||||||
ClearPlainTextEdit::ClearPlainTextEdit(QWidget *parent) :
|
ClearPlainTextEdit::ClearPlainTextEdit(QWidget *parent) :
|
||||||
QPlainTextEdit(parent),
|
QPlainTextEdit(parent),
|
||||||
ButtonOverlay(this)
|
ButtonOverlay(viewport())
|
||||||
{
|
{
|
||||||
// set alignment to show buttons in the bottom right corner
|
// set alignment to show buttons in the bottom right corner
|
||||||
ButtonOverlay::buttonLayout()->setAlignment(Qt::AlignBottom | Qt::AlignRight);
|
ButtonOverlay::buttonLayout()->setAlignment(Qt::AlignBottom | Qt::AlignRight);
|
||||||
ButtonOverlay::setClearButtonEnabled(true);
|
ButtonOverlay::setClearButtonEnabled(true);
|
||||||
connect(document(), &QTextDocument::contentsChanged, this, &ClearPlainTextEdit::handleTextChanged);
|
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();
|
cursor.removeSelectedText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClearPlainTextEdit::handleScroll()
|
||||||
|
{
|
||||||
|
buttonLayout()->update();
|
||||||
|
}
|
||||||
|
|
||||||
bool ClearPlainTextEdit::isCleared() const
|
bool ClearPlainTextEdit::isCleared() const
|
||||||
{
|
{
|
||||||
return document()->isEmpty();
|
return document()->isEmpty();
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void handleTextChanged();
|
void handleTextChanged();
|
||||||
void handleClearButtonClicked();
|
void handleClearButtonClicked();
|
||||||
|
void handleScroll();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue