Skip to content

Commit

Permalink
新增文本框回车焦点下移
Browse files Browse the repository at this point in the history
  • Loading branch information
feiyangqingyun committed Oct 28, 2019
1 parent 62a789c commit b73fa9e
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 135 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
| 18 | saveruntime | 运行时间记录类 |
| 19 | colorwidget | 颜色拾取器 |
| 20 | maskwidget | 遮罩层窗体 |
| 21 | battery | 电池电量控件 |
| 21 | battery | 电池电量控件 |
| 22 | lineeditnext | 文本框回车焦点下移 |
31 changes: 31 additions & 0 deletions lineeditnext/lineeditnext.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#-------------------------------------------------
#
# Project created by QtCreator 2019-10-28T13:44:49
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = lineeditnext
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0


SOURCES += main.cpp\
widget.cpp

HEADERS += widget.h

FORMS += widget.ui
11 changes: 11 additions & 0 deletions lineeditnext/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "widget.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();

return a.exec();
}
30 changes: 30 additions & 0 deletions lineeditnext/widget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "widget.h"
#include "ui_widget.h"
#include "qlineedit.h"

Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
connect(ui->lineEdit1, SIGNAL(returnPressed()), this, SLOT(next()));
connect(ui->lineEdit2, SIGNAL(returnPressed()), this, SLOT(next()));
connect(ui->lineEdit3, SIGNAL(returnPressed()), this, SLOT(next()));
}

Widget::~Widget()
{
delete ui;
}

void Widget::next()
{
QLineEdit *lineEdit = (QLineEdit *)sender();
if (lineEdit == ui->lineEdit1) {
ui->lineEdit2->setFocus();
} else if (lineEdit == ui->lineEdit2) {
ui->lineEdit3->setFocus();
} else if (lineEdit == ui->lineEdit3) {
ui->lineEdit1->setFocus();
}
}
25 changes: 25 additions & 0 deletions lineeditnext/widget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
Q_OBJECT

public:
explicit Widget(QWidget *parent = 0);
~Widget();

private:
Ui::Widget *ui;

private slots:
void next();
};

#endif // WIDGET_H
50 changes: 50 additions & 0 deletions lineeditnext/widget.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Widget</class>
<widget class="QWidget" name="Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Widget</string>
</property>
<widget class="QLineEdit" name="lineEdit1">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit2">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit3">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
134 changes: 0 additions & 134 deletions styledemo/readme.txt

This file was deleted.

0 comments on commit b73fa9e

Please sign in to comment.