Milen
Milen

Reputation: 81

A QSplitter and finding the current widget

I have a QSplitter with four QTextEdit widgets inside. I know that I can use QObject::findChildren to receive a list with all the widgets inside a widget (in my case in the QSplitter) but I can't figure it out how to determine which is the current one?

Upvotes: 2

Views: 517

Answers (1)

Daniel Castro
Daniel Castro

Reputation: 1290

As said in the comments, you were looking for the QTextEdit with the focus, so there are two options, basically:

  1. Use QApplication::focusWidget() (http://doc.qt.digia.com/qt/qapplication.html#focusWidget)
  2. Loop through every child of your QSplitter and call hasFocus() for each one so you can know which of them has the focus (keyboard focus)

The main disadvantage of the first approach is that you can't be sure (using it directly) whether that widget belongs to the QSplitter or not. The second approach may sound a bit inefficent, but if your QSplitter does not have many widgets, then it will be perfectly fine.

As pointed in the comments (of the OP), you have chosen the second approach, and I'm the one posting the answer here because the OP didn't have enough reputation to answer his question.

Upvotes: 2

Related Questions