Qt_4 - 8BitsCoding/RobotMentor GitHub Wiki

spinbox와 slider 사용해보기

spinbox, slider 넣기

#include <QtCore/QCoreApplication>
#include <QtWidgets/qapplication.h>
#include <QtWidgets/qspinbox.h>
#include <QtWidgets/qslider.h>
#include <QtWidgets/QHBoxLayout>
#include <qobject.h>

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);

	QWidget* window = new QWidget;
	QSpinBox* spinBox = new QSpinBox;
	QSlider* slier = new QSlider(Qt::Horizontal);

	spinBox->setRange(0, 100);
	slier->setRange(0, 100);

	QHBoxLayout* layout = new QHBoxLayout;
	layout->addWidget(spinBox);
	layout->addWidget(slier);

	window->setLayout(layout);
	window->show();

	return a.exec();
}

이미지


signal and slot 기능 넣기

#include <QtCore/QCoreApplication>
#include <QtWidgets/qapplication.h>
#include <QtWidgets/qspinbox.h>
#include <QtWidgets/qslider.h>
#include <QtWidgets/QHBoxLayout>
#include <qobject.h>

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);

	QWidget* window = new QWidget;
	QSpinBox* spinBox = new QSpinBox;
	QSlider* slier = new QSlider(Qt::Horizontal);

	spinBox->setRange(0, 100);
	slier->setRange(0, 100);

	QObject::connect(spinBox, SIGNAL(valueChanged(int)), slier, SLOT(setValue(int)));
	QObject::connect(slier, SIGNAL(valueChanged(int)), spinBox, SLOT(setValue(int)));

	QHBoxLayout* layout = new QHBoxLayout;
	layout->addWidget(spinBox);
	layout->addWidget(slier);

	window->setLayout(layout);
	window->show();

	return a.exec();
}
⚠️ **GitHub.com Fallback** ⚠️