Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Child widget steals parent widget's focus
Forum Updated to NodeBB v4.3 + New Features

Child widget steals parent widget's focus

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 332 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    Qt Version: 6.6.3
    Env: Windows 11

    Suppose 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:
    ef678f70-802e-4e96-b6a1-5a2243d601d6-image.png

    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.

    Pl45m4P 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • ? A Former User

        Qt Version: 6.6.3
        Env: Windows 11

        Suppose 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:
        ef678f70-802e-4e96-b6a1-5a2243d601d6-image.png

        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.

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @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 a QMdiArea?

        • https://doc.qt.io/qt-6/qmdisubwindow.html#details

        Or some container widget? Like QStackedWidget / QTabWidget?


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved