Child widget steals parent widget's focus
-
Qt Version: 6.6.3
Env: Windows 11Suppose that I have a parent widget:
CentralWidget::CentralWidget(QMainWindow* mw, QWidget* parent) : QWidget(parent) { ui.setupUi(this); }
Then I add a new child widget as its child, let's say the child widget is a QDialog because I want to make it overlap its parent:
CentralWidget::CentralWidget(QMainWindow* mw, QWidget* parent) : QWidget(parent) { ui.setupUi(this); QDialog* childDialog = new QDialog(this); childDialog->show(); }
That results in the child widget stealing the parent widget's focus when I continue operation on the child widget:
What If I want to make them both focused or the parent window's focus never lost?
I can make the child widget frameless as a floating part of the parent widget.I've tried WindowDoesNotAcceptFocus, and this results in the QLineEdit being disabled.
What do I do if I want to make a floating widget as a part of the parent widget while it does not steal the parent's focus?
Answers not changing the title bar are always preferred, cus using third-party frameless windows can cause bugs. -
Hi,
You can't have two widgets with focus at the same time.
Note that QDialog might not be the best choice as it has specific behavior due to its nature. You should rather use QWidget as a base for that part of your code if you want your extra widget to be within its parent. -
Qt Version: 6.6.3
Env: Windows 11Suppose that I have a parent widget:
CentralWidget::CentralWidget(QMainWindow* mw, QWidget* parent) : QWidget(parent) { ui.setupUi(this); }
Then I add a new child widget as its child, let's say the child widget is a QDialog because I want to make it overlap its parent:
CentralWidget::CentralWidget(QMainWindow* mw, QWidget* parent) : QWidget(parent) { ui.setupUi(this); QDialog* childDialog = new QDialog(this); childDialog->show(); }
That results in the child widget stealing the parent widget's focus when I continue operation on the child widget:
What If I want to make them both focused or the parent window's focus never lost?
I can make the child widget frameless as a floating part of the parent widget.I've tried WindowDoesNotAcceptFocus, and this results in the QLineEdit being disabled.
What do I do if I want to make a floating widget as a part of the parent widget while it does not steal the parent's focus?
Answers not changing the title bar are always preferred, cus using third-party frameless windows can cause bugs.@Richard-Hendricks said in Child widget steals parent widget's focus:
What do I do if I want to make a floating widget as a part of the parent widget while it does not steal the parent's focus?
Maybe
QMdiSubWindow
inside aQMdiArea
?Or some container widget? Like
QStackedWidget
/QTabWidget
?