Results 1 to 13 of 13

Thread: QlineEdit is not showing the Current Focused Widget,

  1. #1
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QlineEdit is not showing the Current Focused Widget,

    Hi, Developer Friends,

    I am In A Problem since last few Days, I Have 800*480 Touch LCD. I am developing a GUI in which i need to configure a network parameters. For this I have two types of widget, One is Dynamic and another is Static.

    Now, i am editing Ethernet parametrs on Static Page,which i am showing and hiding upon requrement . I have 3 QLineEdit box on this static Page,(1) IP (2) Gateway (3) SubnetMask and thrre Pushbutton namely Save, Clear And Cancel.

    When i finished editing these three lines , i push Save. So Application gives the Success/Failure Message on the Dynamic screen, Which Is Constructed and Deleted .
    When Dynamic Message comes ,i Hide the Static Page and shows the Dynamic Page by constructing and after 3 seconds it will be deleted. Again Static Page will be shown.

    At this stage, When Again i am trying to Editing any of LineEdit, None is getting the Focus. So, i can not typed the value, received by current page into the respective Line.

    I am using the QLineEdit . I dont want to use derived class from QLineEdit. I am struggling to find out, which widget got the Focus?

    Thanks .

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QlineEdit is not showing the Current Focused Widget,

    At this stage, When Again i am trying to Editing any of LineEdit, None is getting the Focus
    Even if you click/tap on it?
    Or do you mean that it don't get the focus automatically when the dialog gets shown?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QlineEdit is not showing the Current Focused Widget,

    Ya,

    Even i press/click on it, than also it is not getting the focus.

    I have also tried to setFocus ForceFully on first Line when the Ethernet static page gets showed, using ShowEvent(QEvent *).

    Qt Code:
    1. :: ShowEvent(Event *e)
    2. {
    3. qDebug("static Widget shown");
    4. Ip.SetFocus();
    5.  
    6. if(Ip.hasFocus())
    7. {
    8. qDebug("Ip Line Has Focus"); //Cant reach to this line
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 


    The second thing i Marked is if i disable the Dynamic Screen, Than There Is No problem at All.

    But, i just didnt get who is stalling the Focus ? I can say, Probably a dynamic page is stealing Focus. But i have given NoFocus Policy to a dynamic Screen.

    I am totally lost in this.
    Last edited by high_flyer; 18th December 2010 at 13:32. Reason: code tags

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QlineEdit is not showing the Current Focused Widget,

    is your 'Dynamic screen' modal?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QlineEdit is not showing the Current Focused Widget,

    Thanks for ur reply.

    But, i am not getting. what do u want to say?

    Let me clarify, Dynamic screen is just a widget(Creating every time on need), upon which i am setting User InFormation or messages like Success or Any Image.

    So i just Put all the subwidgets and sets the parameteres And when the next Static Page need to show, This Dynamic widget with its child widgets will be deleted.When i need it again, i contrcts it and delete it.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QlineEdit is not showing the Current Focused Widget,

    Please post the header file of your dynamic widgte.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QlineEdit is not showing the Current Focused Widget,

    Dear High_flyer,

    Here i am putting the Header and source file code.

    file:dynscrn.h

    Qt Code:
    1. class dynscrn : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5.  
    6. dynscrn(QStringList str, int msgid, QWidget *parent=0);
    7. ~dsynsrn();
    8.  
    9. QWidget *dynwid;
    10. QGraphicsProxyWidget *proxy;
    11.  
    12. QLabel *info1;
    13. QLabel *info2;
    14. }
    To copy to clipboard, switch view to plain text mode 
    //////////////////////////////////////////////////////////////////////////////////////////
    File: dynscrn.CPP

    Qt Code:
    1. dynscrn :: dynscrn(QStringList str, int msgid, QWidget *parent=0):QWidget(parent)
    2. {
    3. dynwid = new QWidget(); //Widget on which i paste my text or Image
    4. dynwid -> setGeoMetry(0,0,460,570);
    5. dynwid -> setWindowOpacity(0.75);
    6.  
    7. info1 = new QLabel(dynwid );
    8. info2 = new QLabel(dynwid );
    9.  
    10. info1 -> setText(str.at(0));
    11. info2 -> setText(str.at(1));
    12.  
    13. //rotate above dynwid
    14. scene =new QGraphicsScene();
    15. proxy = scene -> addWidget(dynwid );
    16. view = new QGraphicsView(scene);
    17. view -> setParent( parent, Qt::FrameLessWindowHint);
    18. view ->setFixedSize(570+4, 460+4);
    19. view -> setGeoMetry(0,0,570,460); //change the width and height
    20.  
    21. view -> rotate(-90); //rotate at -90
    22. view -> show(); //display dynwid
    23. }
    24.  
    25. dsynsrn ::~dsynsrn() //deletes whole dynwid and its children
    26. {
    27. delete info1;
    28. delete info2;
    29. delete dynwid;
    30. delete scene;
    31. delete view;
    32. }
    To copy to clipboard, switch view to plain text mode 

    /////////////////////////////////////////////////////////////////////////
    Now in Another Class File I used this as below:
    In this Both dynamic and static screen object will be used as per requirement.

    Qt Code:
    1. void Widget:: RxMessageAtQt(messgeid, stringlist)
    2. {
    3.  
    4. if(static Screen is visible)
    5. {
    6. hide static screen;
    7. }
    8.  
    9. if(dynscrn is object ! = NULL) //means dynamic widget is currently exist
    10. {
    11.  
    12. delete dynamic widget;
    13. dynamic widget = NULL;
    14. }
    15.  
    16. if(messageid == 500) //show dynamic scrn
    17. {
    18. create a dynamic widget from dynscrn and will be displayed by its constructor;
    19. }
    20. else //show static screen
    21. {
    22. if(static screen is not visible)
    23. {
    24. show static screen;
    25. // Static screen is a statcked of widgets.Its basically a Menu, and we can
    26. // navigate by the button on that screen.
    27. //User can enter some valued like ethernet parameters and save ,delete and
    28. // cancel it. or move to the next or previous menu widget.
    29. //Thede are not editable when i come second time over this page.
    30. }
    31. }
    32.  
    33.  
    34. }
    To copy to clipboard, switch view to plain text mode 

    /*************end *******************


    I cant find any bug in the above code.
    If some one knows let know.

    THANKING YOU ALL.
    Last edited by high_flyer; 17th December 2010 at 09:53. Reason: code tags

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QlineEdit is not showing the Current Focused Widget,

    I cant find any bug in the above code.
    Please post REAL code, not pseudo code, as the devil is in details!

    Why don't just use a dialog, and use show() and hide() instead creating and deleting your dynamic widget?
    Last edited by high_flyer; 17th December 2010 at 10:02.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QlineEdit is not showing the Current Focused Widget,

    Why don't just use a dialog, and use show() and hide() instead creating and deleting your dynamic widget?

    Because i Do also need to show some photos . Let say User name, User type and his Image. Than how can i put the image on QDialog ?

    I have Another Doubt:

    Assume i have only one Static Page. And its Focus Policy is Qt::ClickFocus.

    when this widget gets showed, i do widget.setFocus();
    and than
    Qt Code:
    1. if(widget.hasFocus())
    2. {
    3. qDebug()<<"Has the Focus";
    4. }
    5. else
    6. {
    7. qDebug()<<"No Focus";
    8. }
    To copy to clipboard, switch view to plain text mode 

    The above code always give me "No Focus". why so? I am Amazed.

    Dear High_Flyer its not possible for me to put the header and source . I am Really sorry.
    But i can give you Related/Respective Information if u have the hint at any of the above.
    Last edited by high_flyer; 17th December 2010 at 14:37.

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QlineEdit is not showing the Current Focused Widget,

    Because i Do also need to show some photos . Let say User name, User type and his Image. Than how can i put the image on QDialog ?
    You subclass it just like you subclass QWidget, and add anything you want to it.

    You code is very hard to follow, and its unnecessarily complex in my opinion.
    Just use a QDialog, show() and hide() I am sure your problem will go away this way, and your code will be smaller too.

    P.S
    And PLEASE use the code tags, its hard to read the code this way.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QlineEdit is not showing the Current Focused Widget,

    Thanks for your reply.

    Let me try it.

  12. #12
    Join Date
    May 2010
    Posts
    100
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QlineEdit is not showing the Current Focused Widget,

    Dear High_Flyer,

    I got the Reason, why i cant edit in the field when i come secong time at the static page.

    In my design, If i didnt hide the static page and shows the dynamic screen on top of static screen. Than there is no problem.

    But i am not getting why my last static page field is losing the focus, and also forcefully i can't set the focus.

    I Have also tried with QDialog, But in that case also if i hide the static page and shows the Dialog screen. Than also there is same problem.

    In short if i will hide the static page, it is always going to lost the focus. And not possible to set the focus again.

    Can u please, now tell me what should i do to set the focus. In my design i have gone so away ,that i cant change the design.

  13. #13
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QlineEdit is not showing the Current Focused Widget,

    Frankly, I have trouble following the logic in your code and explanations.
    And at least what you posted so far is very "scatchy" for me to see a specific one problem.
    Again, instead of creating and deleting your dynamic widget, just use show() and hide() for it. (if you don't want to work with QDialog)
    It is better for many reasons in comparison to creating deleting it all the time.
    In addition to dangerous thins as not checking pointers have a look at this (see comments in code:
    Qt Code:
    1. if(static Screen is visible)
    2. {
    3. hide static screen;
    4. }
    5.  
    6. if(dynscrn is object ! = NULL) //means dynamic widget is currently exist
    7. {
    8.  
    9. delete dynamic widget;
    10. dynamic widget = NULL;
    11. }
    12.  
    13. //you are showing (and for you showing = creating) a new dynamic widget, even if the
    14. // 'if' above was not true, resulting in a memory leak at best, and maybe other
    15. //problems such as you focus problems at worst.
    16. if(messageid == 500) //show dynamic scrn
    17. {
    18. create a dynamic widget from dynscrn and will be displayed by its constructor;
    19. }
    20. else //show static screen
    21. {
    22. ...
    23. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 4
    Last Post: 29th September 2010, 20:21
  2. Replies: 0
    Last Post: 11th August 2010, 11:02
  3. Widget not showing
    By kaushal_gaurav in forum Qt Programming
    Replies: 3
    Last Post: 24th July 2008, 10:37
  4. Showing the output from cmake on my widget
    By jsmax in forum Qt Programming
    Replies: 3
    Last Post: 18th May 2007, 21:17
  5. Replies: 1
    Last Post: 6th November 2006, 00:50

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.