Qt Creator에서 버튼과 텍스트를 출력해 보겠다.
Qt에서 cpp파일을 하나 만들고 코드를 넣고 실행시키면 된다.
텍스트를 출력하려면 QPushButton이라는 헤더 파일이 필요하다.
#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QPushButton>
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("클릭하세요", &window); // button
button.move(500, 500); // button position
window.show();
return app.exec();
}
이렇게 버튼을 만들어보았다. 하지만 눈이 침침하기도 하고 버튼이 너무 작기도 하여서 버튼 설정은 한번 바꿔보자.
QPushButton button("클릭하세요", &window);
button.move(500, 500);
button.resize(100, 50); // button size
window.show();
resize로 사이즈를 늘려보았다.
왕건이 버튼을 만드니 눈이 침침해서 못 누를 일을 없을 거 같다. 하지만 클릭하세요 글자가 너무 작아서 잘 안 보인다. 이것도 수정을 해보자.
글자 폰트사이즈를 바꾸려면 QFont라는 헤더 파일이 필요하다.
#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QFont>
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("클릭하세요", &window); // button
QFont buttonFont = button.font();
buttonFont.setPointSize(16); // button text size
button.setFont(buttonFont);
button.move(500, 500); // button position
button.resize(500, 500); // Set button size
window.show();
return app.exec();
}
정말 잘 보인다

728x90
'Qt' 카테고리의 다른 글
[Qt] 텍스트 입력란 (0) | 2024.10.16 |
---|---|
[Qt] 버튼 클릭 이벤트 (1) | 2024.10.16 |
[Qt] 텍스트 출력 (0) | 2024.10.16 |
[Qt] 빈 창 만들기 (0) | 2024.10.16 |
[Qt] Qt란? (1) | 2024.10.16 |