QLineEdit: Unable to drag selected text when aligned right or center

Created local inSelection function to modify the x value (similar to
xToPos()) before sending it to the control. Ran the QLineEdit test and
manually tested with AlignLeft, AlignRight and AlignCenter.

Change-Id: I088430580dc87f3cfff90c4cd9ff90e6ab215f57
Task-number: QTBUG-48495
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Dan Cape 2015-10-06 14:00:15 -04:00 committed by Giuseppe D'Angelo
parent 9636d8bee0
commit e56938b4bb
3 changed files with 8 additions and 1 deletions

View File

@ -1488,7 +1488,7 @@ void QLineEdit::mousePressEvent(QMouseEvent* e)
int cursor = d->xToPos(e->pos().x());
#ifndef QT_NO_DRAGANDDROP
if (!mark && d->dragEnabled && d->control->echoMode() == Normal &&
e->button() == Qt::LeftButton && d->control->inSelection(e->pos().x())) {
e->button() == Qt::LeftButton && d->inSelection(e->pos().x())) {
if (!d->dndTimer.isActive())
d->dndTimer.start(QApplication::startDragTime(), this);
} else

View File

@ -70,6 +70,12 @@ int QLineEditPrivate::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const
return control->xToPos(x, betweenOrOn);
}
bool QLineEditPrivate::inSelection(int x) const
{
x -= adjustedContentsRect().x() - hscroll + horizontalMargin;
return control->inSelection(x);
}
QRect QLineEditPrivate::cursorRect() const
{
return adjustedControlRect(control->cursorRect());

View File

@ -139,6 +139,7 @@ public:
QRect adjustedControlRect(const QRect &) const;
int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const;
bool inSelection(int x) const;
QRect cursorRect() const;
void setCursorVisible(bool visible);