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 .
Re: QlineEdit is not showing the Current Focused Widget,
Quote:
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?
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 *).
Code:
:: ShowEvent(Event *e)
{
qDebug("static Widget shown");
Ip.SetFocus();
if(Ip.hasFocus())
{
qDebug("Ip Line Has Focus"); //Cant reach to this line
}
}
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.
Re: QlineEdit is not showing the Current Focused Widget,
is your 'Dynamic screen' modal?
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.
Re: QlineEdit is not showing the Current Focused Widget,
Please post the header file of your dynamic widgte.
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
Code:
{
Q_OBJECT
public:
~dsynsrn();
QGraphicsProxyWidget *proxy;
}
//////////////////////////////////////////////////////////////////////////////////////////
File: dynscrn.CPP
Code:
{
dynwid
= new QWidget();
//Widget on which i paste my text or Image dynwid -> setGeoMetry(0,0,460,570);
dynwid -> setWindowOpacity(0.75);
info1 -> setText(str.at(0));
info2 -> setText(str.at(1));
//rotate above dynwid
proxy = scene -> addWidget(dynwid );
view -> setParent( parent, Qt::FrameLessWindowHint);
view ->setFixedSize(570+4, 460+4);
view -> setGeoMetry(0,0,570,460); //change the width and height
view -> rotate(-90); //rotate at -90
view -> show(); //display dynwid
}
dsynsrn ::~dsynsrn() //deletes whole dynwid and its children
{
delete info1;
delete info2;
delete dynwid;
delete scene;
delete view;
}
/////////////////////////////////////////////////////////////////////////
Now in Another Class File I used this as below:
In this Both dynamic and static screen object will be used as per requirement.
Code:
void Widget:: RxMessageAtQt(messgeid, stringlist)
{
if(static Screen is visible)
{
hide static screen;
}
if(dynscrn is object ! = NULL) //means dynamic widget is currently exist
{
delete dynamic widget;
dynamic widget = NULL;
}
if(messageid == 500) //show dynamic scrn
{
create a dynamic widget from dynscrn and will be displayed by its constructor;
}
else //show static screen
{
if(static screen is not visible)
{
show static screen;
// Static screen is a statcked of widgets.Its basically a Menu, and we can
// navigate by the button on that screen.
//User can enter some valued like ethernet parameters and save ,delete and
// cancel it. or move to the next or previous menu widget.
//Thede are not editable when i come second time over this page.
}
}
}
/*************end *******************
I cant find any bug in the above code.
If some one knows let know.
THANKING YOU ALL.
Re: QlineEdit is not showing the Current Focused Widget,
Quote:
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?
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
Code:
if(widget.hasFocus())
{
qDebug()<<"Has the Focus";
}
else
{
qDebug()<<"No Focus";
}
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.
Re: QlineEdit is not showing the Current Focused Widget,
Quote:
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.
Re: QlineEdit is not showing the Current Focused Widget,
Thanks for your reply.
Let me try it.
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.
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:
Code:
if(static Screen is visible)
{
hide static screen;
}
if(dynscrn is object ! = NULL) //means dynamic widget is currently exist
{
delete dynamic widget;
dynamic widget = NULL;
}
//you are showing (and for you showing = creating) a new dynamic widget, even if the
// 'if' above was not true, resulting in a memory leak at best, and maybe other
//problems such as you focus problems at worst.
if(messageid == 500) //show dynamic scrn
{
create a dynamic widget from dynscrn and will be displayed by its constructor;
}
else //show static screen
{
...
}