如何获取光标当前位置的编号(qt) [英] how to get number of the current position of the cursor (qt)

查看:52
本文介绍了如何获取光标当前位置的编号(qt)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一点帮助,我正在使用 qt 中的 Qslider 类,如何获取光标当前位置的编号(使用哪个函数可以做到),请提前致谢

I need small help, I'm using class Qslider from qt, how can I get the number of the current position of the cursor (with which function I can do that) thanks in advance

我想实现一件事:当我达到我想退出的间隔的最大值时,我该如何使用插槽和信号来做到这一点?

I want to implement one thing: when I reach the max of the interval I want to quit, how can I do this with slot and signal?

推荐答案

我假设您想要滑块的值?

I am assuming you want the value of the slider?

int QSlider::value ()

我查看了您另一篇文章中的代码,这是我清理后想到的:

I looked at the code in your other post and this is what I came up with after cleaning it up:

ma​​in.cpp

#include <QApplication>
#include "mywidget.h"

int main(int argc, char *argv[])
{
 QApplication app(argc, argv);
 MyWidget widget;
 widget.show();
 return app.exec();
}

mywidget.h

 #ifndef MYWIDGET_H
 #define MYWIDGET_H
 #include <QWidget>
 #include <QObject>
 include <QPushButton>
 #include <QSlider>

 class MyWidget : public QWidget
 {
  Q_OBJECT
  public:
MyWidget(QWidget *parent = 0);
~MyWidget(){};
  public slots:
void getSliderValueAndQuit();
  private:
 QPushButton *quit;
 QSlider *slider;
 };

 #endif // MYWIDGET_H

myWidget.cpp

 #include "mywidget.h"
 #include <QWidget>
 #include <QObject>
 #include <QApplication>
 #include <QFont>
 #include <QLCDNumber>
 #include <QPushButton>
 #include <QSlider>
 #include <QVBoxLayout>

 MyWidget::MyWidget(QWidget *parent) :
 QWidget(parent)
 {
quit = new QPushButton(tr("Quit"));
quit->setFont(QFont("Times", 18, QFont::Bold));

QLCDNumber *lcd = new QLCDNumber(3);
lcd->setSegmentStyle(QLCDNumber::Flat);

slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 999);
slider->setValue(0);

connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));

connect(slider, SIGNAL(valueChanged(int)),lcd, SLOT(display(int)));
connect(slider,SIGNAL(sliderReleased()), SLOT(getSliderValueAndQuit()));

QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(quit);
layout->addWidget(lcd);
layout->addWidget(slider);
setLayout(layout);
 }

 void MyWidget::getSliderValueAndQuit(){
if(slider->value() == slider->maximum())
    close();
 }

这篇关于如何获取光标当前位置的编号(qt)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆