Qt Creator에서 이번에는 InputField를 만들어보자.
InputField를 만들기 위해서는 QLineEdit이라는 헤더 파일이 필요하다.
아래 코드는 InputField의 기본 형태이다.
// 기본 형태
#include <QLineEdit>
QLineEdit inputField(&window);
inputField.move(350, 200); // position
inputField.resize(100, 30); // size
#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QFont>
#include <QObject>
#include <QLineEdit>
void onButtonCilcked(){
qInfo("Button clicked!");
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(1920, 1080); // window size
window.setWindowTitle("Empty window"); // widow name
QLabel label("Minit blog!", &window); // text
label.move(300, 300); // text position
QPushButton button("Button", &window); // button
QFont buttonFont = button.font();
buttonFont.setPointSize(20); // button text size
button.setFont(buttonFont);
button.move(500, 100); // button position
button.resize(500, 500); // button size
QObject::connect(&button, &QPushButton::clicked, &onButtonCilcked); // button click event
QLineEdit inputfield(&window);
inputfield.move(1200, 100); // input text position
inputfield.resize(500, 500); // input text size
QFont inputFont = inputfield.font();
inputFont.setPointSize(20); // input text size
inputfield.setFont(inputFont);
window.show();
return app.exec();
}
원래는 빈 field이지만 "text를 입력하세요!"라고 적어보았다. 여기서 궁금증이 생긴다. 그럼 기본 default값을 바꿀 수 있을까? 바꾸려고 하면 아래 함수를 사용하면 된다.
inputfield.setPlaceholderText("default text");
728x90
'Qt' 카테고리의 다른 글
[Qt] qmake란? (0) | 2024.10.16 |
---|---|
[Qt] 배경색 변경 (0) | 2024.10.16 |
[Qt] 버튼 클릭 이벤트 (1) | 2024.10.16 |
[Qt] 버튼 만들기 (0) | 2024.10.16 |
[Qt] 텍스트 출력 (0) | 2024.10.16 |