Results 1 to 14 of 14

Thread: QTextEdit hasFocus() not working on linux

  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QTextEdit hasFocus() not working on linux

    Hi guys,
    First let me tell that the problem is on fedora (linux) but works fine on windows.

    Please find the attached file for source code. There is a textedit.pro and I have created an ./textEdit incase if the program doesnt run...

    I have two QTextEdits displayed on QMainWindow. I have also provided a menuItem "Insert" on the QMainWindow. When you run the program Initially the cursor will be fucossed to first QTextEdit( above ). Now when I click on "insert" menuItem a dockwindow is displayed with some image. The cursor is disappeared from first QTextEdit(on linux). I dont know why??

    Now what I want is when I click on dockwindow(on Image), If the focus is on first QTextEdit the focus should go to second QTextEdit(below) and vice versa (i.e switch to other)

    Is there any problem with setFocus as given in the code.

    The code works fine on windows but on linux the focus is disappearing because of which the switching is not happening...

    Please help me

    Details about file attached.

    Contains

    test.h //for textEdit
    test.cpp //for textEdit
    chemheaderfooteroption.cpp //for dockwindow
    chemheaderfooteroption.h //for dockwindow
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit hasFocus() not working on linux

    Quote Originally Posted by vermarajeev View Post
    The code works fine on windows but on linux the focus is disappearing because of which the switching is not happening...
    AFAIK the behaviour is perfectly normal and is a result of different focus handling policies on both platforms. There is a difference between an active window and a focused window, so when you click on some other window making it active, the focus in moved with it on Linux but not on Windows. Qt just follows the platform convention here.

  3. #3
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit hasFocus() not working on linux

    Quote Originally Posted by wysota View Post
    AFAIK the behaviour is perfectly normal and is a result of different focus handling policies on both platforms. There is a difference between an active window and a focused window, so when you click on some other window making it active, the focus in moved with it on Linux but not on Windows. Qt just follows the platform convention here.
    So, how should I solve the above problem on linux. I want the focus to be there on TextEdit when the dock window becomes active....

    Or is there any other thing I can do....

    Please help me

    thankx in advance

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit hasFocus() not working on linux

    Maybe you don't need that focus after all? Maybe it is enough to track which of the text edits had the focus last? Connecting to the focusChanged() signal of QApplication and storing a pointer to the active widget (if it is one of your text edits) should do the thing nicely. I remember I used such a trick once and it was working ok.

  5. #5
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit hasFocus() not working on linux

    Quote Originally Posted by wysota View Post
    Maybe you don't need that focus after all? Maybe it is enough to track which of the text edits had the focus last? Connecting to the focusChanged() signal of QApplication and storing a pointer to the active widget (if it is one of your text edits) should do the thing nicely. I remember I used such a trick once and it was working ok.
    I cannot find focusChanged() in Qt3.3.5

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit hasFocus() not working on linux

    Right... it's from Qt4. In Qt3 you can achieve the same by applying event filters to both text edits and catching focusIn events.

  7. #7
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit hasFocus() not working on linux

    Quote Originally Posted by wysota View Post
    Right... it's from Qt4. In Qt3 you can achieve the same by applying event filters to both text edits and catching focusIn events.
    I just tried as you said.
    I have done like this

    Qt Code:
    1. firstTextEdit->installEventFilter( this ); //this indicates my QMainwindow
    2. secondTextEdit->installEventFilter( this );
    To copy to clipboard, switch view to plain text mode 

    then in
    Qt Code:
    1. bool MainWindow::eventFilter( QObject *obj, QEvent *e )
    2. {
    3. if ( obj == firstTextEdit && e->type() == QEvent::FocusIn )
    4. _first = true;
    5. else
    6. _first = false;
    7. }
    8. //_first is member variable which tells that the previous focusIn was of firstTextEdit
    9. Then I check the boolean value in the slot that I have defined
    10.  
    11. void MainWindow::switch()
    12. {
    13. if(_first)
    14. second->setFocus();
    15. else
    16. first->setFocus();
    17. }
    To copy to clipboard, switch view to plain text mode 
    But still the problem is that the cursor is not visible. When I check this condition
    if(_first)
    second->setFocus();
    else
    first->setFocus();

    if _first is true then the focus should be on second but since the doxkwindow is active the cursor is not visible.

    Please give me some more suggestions wysota...

    Thankx in advance

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit hasFocus() not working on linux

    Check if your event filter is triggered and with what arguments. Also don't try to force the focus this way, it won't work. Instead just make the action on a proper widget based on the last focused text edit. You might also try using setActiveWindow (or something simmilar, I don't remember the exact name now) too.

  9. #9
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit hasFocus() not working on linux

    Quote Originally Posted by wysota View Post
    Check if your event filter is triggered and with what arguments. Also don't try to force the focus this way, it won't work. Instead just make the action on a proper widget based on the last focused text edit. You might also try using setActiveWindow (or something simmilar, I don't remember the exact name now) too.
    Hi wysota,
    Thankx for your understanding

    As per your comments
    "Also don't try to force the focus this way, it won't work. Instead just make the action on a proper widget based on the last focused text edit. You might also try using setActiveWindow (or something simmilar, I don't remember the exact name now) too."

    Please help me to implement this. I will be thankful to you if you can provide some code example.

    Thankx

  10. #10
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Thanks
    3
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit hasFocus() not working on linux

    I decided to do away with QT3 support in my QT4.2.2 installation so I compiled 4.2.2 without QT3 support. When I compiled my app all my "gotFocus()", "lostFocus()" and related triggers and events stopped working.

    QT Support says that QT4.2.2 doesn't have got those events on controls. Dropping them was a BIG Mistake, IMO. I reconfigured and compiled QT 4.2.2 WITH QT3 support so my apps would compile and run properly again.

  11. #11
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit hasFocus() not working on linux

    Hi wyosta,
    Eagerly waiting for your reply. I'm just stuck here and is in need of your suggestions. Can you please help to solve this probelm. I'll be really thankful to you.

    Waiting for a reply

    Thankx

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit hasFocus() not working on linux

    Example attached. Click on one of the text edits, then click on the empty QWidget to make the text edit loose focus, then click on the push button.
    Attached Files Attached Files

  13. The following user says thank you to wysota for this useful post:

    vermarajeev (28th December 2006)

  14. #13
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit hasFocus() not working on linux

    Quote Originally Posted by wysota View Post
    Example attached. Click on one of the text edits, then click on the empty QWidget to make the text edit loose focus, then click on the push button.
    Hi wysota,
    Thankx a lot, it works...What mistake I was doing is in the eventFilter I was just returning true, hence the focusIn event was ate up....But as the solution you have provided it returns false....

    I have got the output but still I not completely got about return TRUE and return FALSe, I read Qt Assistant and it tells that if you want to stop the event from further processing return TRUE and if not return FALSE...

    Can you clear about that to me.....

    Any way thankx a lot....You are owesome )

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit hasFocus() not working on linux

    That's right. But in this case you don't want to stop event processing - you just want to monitor for occurence of the event, so you need to return false here.

Similar Threads

  1. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  2. Replies: 4
    Last Post: 10th May 2006, 22:37
  3. QProcess / system call not working under linux. Why?
    By johnny_sparx in forum Qt Programming
    Replies: 12
    Last Post: 11th March 2006, 00:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.