Results 1 to 13 of 13

Thread: QlineEdit is not showing the Current Focused Widget,

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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 08:53. Reason: code tags

  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,

    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 09: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.

  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,

    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 13:37.

  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,

    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.

  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 your reply.

    Let me try it.

  6. #6
    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.

  7. #7
    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, 19:21
  2. Replies: 0
    Last Post: 11th August 2010, 10:02
  3. Widget not showing
    By kaushal_gaurav in forum Qt Programming
    Replies: 3
    Last Post: 24th July 2008, 09:37
  4. Showing the output from cmake on my widget
    By jsmax in forum Qt Programming
    Replies: 3
    Last Post: 18th May 2007, 20:17
  5. Replies: 1
    Last Post: 5th November 2006, 23: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.