Dear visitor, welcome to QtForum.org.
If this is your first visit here, please read the Help. It explains in detail how this page works.
To use all features of this page, you should consider registering.
Please use the registration form, to register here or read more information about the registration process.
If you are already registered, please login here.
Using slider values
This is a pretty simple question but I can't figure this out.
I'm playing with a graphic interface and I want the code to work so that when I press OK it prints something (or does anything really) depending on where the slider is set. Later on I would like to make a program where you can use sliders and other things to adjust settings before pressing OK and it uses these chosen settings to call another program with given arguments (so basically a graphic wrapper).
Here is my code so far, where do I go from here?
Widget.cpp
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent), ui(new Ui::Widget)
{
okButton = new QPushButton(tr("OK"), this);
okButton->move(200, 200);
okButton->show();
resBar = new QSlider(Qt::Horizontal, this);
resBar->setFocusPolicy(Qt::StrongFocus);
resBar->setTickPosition(QSlider::TicksBelow);
resBar->setTickInterval(1);
resBar->setSingleStep(0);
resBar->setMinimum(1);
resBar->setMaximum(4);
resBar->move(200,100);
resBar->show();
connect(okButton, SIGNAL(clicked()), this, SLOT(makePrintFile()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::makePrintFile(){
printf("OK pressed");
//What can I put here to make it do something if the value is at 2 (for example)? I tried using resBar->value but that doesn't work.
}
|
Widget.h
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui/QWidget>
#include <QPushButton>
#include <QSlider>
namespace Ui
{
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
public slots:
void makePrintFile();
private:
QPushButton *okButton;
QSlider *resBar;
Ui::Widget *ui;
};
#endif // WIDGET_H
|
I'm not really sure where you are stuck. It seems to me that you just need a case statement or a few if statements like
if (resBar->value() == 1)
{ do something here }
I'm not really sure where you are stuck. It seems to me that you just need a case statement or a few if statements like
if (resBar->value() == 1)
{ do something here }
nevermind i fixed it. Thanks for your help, you're right.
This post has been edited 1 times, last edit by "Jonnyd898" (Jul 24th 2009, 3:48pm)