GUI: fg/bgcolor text edit: fix right-click context menu not working

properly by checking for it on FocusOut
This commit is contained in:
gitlost 2023-01-19 00:11:29 +00:00
parent 6f7cdd660c
commit 48eaa0cc4e
2 changed files with 16 additions and 7 deletions

View File

@ -22,6 +22,8 @@ Bugs
- man page: fix Code 11 check digit info - man page: fix Code 11 check digit info
- CMake: allow ctest to be run without having to install zint or manually set - CMake: allow ctest to be run without having to install zint or manually set
LD_LIBRARY_PATH and PATH (ticket #279, props Alexey Dokuchaev) LD_LIBRARY_PATH and PATH (ticket #279, props Alexey Dokuchaev)
- GUI: fg/bgcolor text edit: fix right-click context menu not working properly
by checking for it on FocusOut
Version 2.12.0 (2022-12-12) Version 2.12.0 (2022-12-12)

View File

@ -552,12 +552,16 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
} }
if ((watched == txt_fgcolor || watched == txt_bgcolor) && event->type() == QEvent::FocusOut) { if ((watched == txt_fgcolor || watched == txt_bgcolor) && event->type() == QEvent::FocusOut) {
// Exclude right-click context menu pop-up (Undo/Redo/Cut/Copy/Paste etc.)
QFocusEvent *focusEvent = static_cast<QFocusEvent *>(event);
if (focusEvent->reason() != Qt::PopupFocusReason) {
if (watched == txt_fgcolor) { if (watched == txt_fgcolor) {
setColorTxtBtn(m_fgcolor, txt_fgcolor, fgcolor); setColorTxtBtn(m_fgcolor, txt_fgcolor, fgcolor);
} else { } else {
setColorTxtBtn(m_bgcolor, txt_bgcolor, bgcolor); setColorTxtBtn(m_bgcolor, txt_bgcolor, bgcolor);
} }
} }
}
return QWidget::eventFilter(watched, event); return QWidget::eventFilter(watched, event);
} }
@ -592,9 +596,12 @@ QString MainWindow::getColorStr(const QColor color, bool alpha_always) {
} }
void MainWindow::setColorTxtBtn(const QColor color, QLineEdit *txt, QPushButton* btn) { void MainWindow::setColorTxtBtn(const QColor color, QLineEdit *txt, QPushButton* btn) {
QString colorStr = getColorStr(color);
if (colorStr != txt->text()) {
int cursorPos = txt->cursorPosition(); int cursorPos = txt->cursorPosition();
txt->setText(getColorStr(color)); txt->setText(colorStr);
txt->setCursorPosition(cursorPos); txt->setCursorPosition(cursorPos);
}
btn->setStyleSheet(QSL("QPushButton {background-color:") + color.name() + QSL(";}")); btn->setStyleSheet(QSL("QPushButton {background-color:") + color.name() + QSL(";}"));
} }