QLineEdit焦点事件
我有两个小部件 mainwindow123 和二等。在我的 MainWidget.cpp 中有一个行编辑和按钮字段。最初我可以将焦点设置在行编辑上。但在来自第二个.cpp 小部件之后,我无法将焦点设置在 lineedit 上。请帮助我..我在哪个地方做错了?提前致谢。
这是我的代码 MainWidget.cpp
MainWidget::MainWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainWidget)
{
ui->setupUi(this);
s = new second();
connect(ui->pushButton, SIGNAL(clicked()),this,SLOT(callSecond()));
}
MainWidget::~MainWidget()
{
delete ui;
}
void MainWidget::callSecond()
{
s->show();
}
第二个.cpp
second::second(QWidget *parent) :
QWidget(parent)
{
QPushButton *first = new QPushButton("first");
first->setStyleSheet(
"background-color:black;"
);
QGridLayout *d = new QGridLayout();
d->addWidget(frist,0,0,1,1);
setLayout(d);
connect(first,SIGNAL(clicked()),this,SLOT(first()));
}
void second:: first()
{
this->hide();
}
I have two widget mainwindow123 and second-class. In my MainWidget.cpp have one lineedit and button field. Initially I can set the focus on the line edit. But after come from the second.cpp Widget then I could not set the focus on the lineedit. Please help me.. Which place I did the mistake? Thanks in advance.
This is my code
MainWidget.cpp
MainWidget::MainWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainWidget)
{
ui->setupUi(this);
s = new second();
connect(ui->pushButton, SIGNAL(clicked()),this,SLOT(callSecond()));
}
MainWidget::~MainWidget()
{
delete ui;
}
void MainWidget::callSecond()
{
s->show();
}
second.cpp
second::second(QWidget *parent) :
QWidget(parent)
{
QPushButton *first = new QPushButton("first");
first->setStyleSheet(
"background-color:black;"
);
QGridLayout *d = new QGridLayout();
d->addWidget(frist,0,0,1,1);
setLayout(d);
connect(first,SIGNAL(clicked()),this,SLOT(first()));
}
void second:: first()
{
this->hide();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为单击按钮后您的焦点会转到按钮上。您可以通过以下方式实现:
It's because your focus goes to button after you clicked it. You could achieve it by: