LINUX.ORG.RU

Сообщения rusooo

 

Qt как сделать slider который меняет значение переменной от min=0 до max=4880

Qt как сделать slider который меняет значение переменной от min=0 до max=4880

написал маленькую програмку для изменения яркости подсветки дисплея и клавиатуры двадцать лет ничего не писал :bandhead: для програмиста это займет несколько минут и не составит большого труда 8-)

всё работает как на рис1, но яркость меняется дискретно

а хотелось бы чтобы менялась плавно слайдером, как на рис2 для дисплея $lcd мин 0 макс 4880 system(«echo $lcd >> /sys/class/backlight/intel_backlight/brightness»);

для клавиатуры $kbd от 0 до 3 system(«echo $kbd >> /sys/devices/platform/asus-nb-wmi/leds/asus\:\:kbd_backlight/brightness»);

рис1 [img=41x176, 6.4Kb]http://storage7.static.itmages.ru/i/13/0721/s_1374391585_1492002_b1f0936c4d.png[/img] рис2 [img=64x176, 7.8Kb]http://storage8.static.itmages.ru/i/13/0721/s_1374391644_1825647_fa7f099c64.png[/img]

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
 
namespace Ui {
class MainWindow;
}
 
class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    
private slots:
    void on_pushButton_clicked();
 
    void on_pushButton_2_clicked();
 
    void on_pushButton_3_clicked();
 
    void on_pushButton_4_clicked();
 
    void on_pushButton_5_clicked();
 
    void on_pushButton_6_clicked();
 
    void on_pushButton_7_clicked();
 
    void on_pushButton_8_clicked();
 
    void on_pushButton_9_clicked();
 
    void on_pushButton_10_clicked();
 
    void on_pushButton_11_clicked();
 
    void on_pushButton_12_clicked();
 
    void on_pushButton_13_clicked();
 
    void on_pushButton_14_clicked();
 
    void on_pushButton_15_clicked();
 
private:
    Ui::MainWindow *ui;
};
 
#endif // MAINWINDOW_H
main.cpp
#include "mainwindow.h"
#include <QApplication>
 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    
    return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}
 
MainWindow::~MainWindow()
{
    delete ui;
}
 
 
void MainWindow::on_pushButton_clicked()
{
    system("echo 488 >> /sys/class/backlight/intel_backlight/brightness");
}
 
void MainWindow::on_pushButton_2_clicked()
{
    system("echo 976 >> /sys/class/backlight/intel_backlight/brightness");
}
 
void MainWindow::on_pushButton_3_clicked()
{
    system("echo 1464 >> /sys/class/backlight/intel_backlight/brightness");
}
 
void MainWindow::on_pushButton_4_clicked()
{
    system("echo 1952 >> /sys/class/backlight/intel_backlight/brightness");
}
 
void MainWindow::on_pushButton_5_clicked()
{
    system("echo 2440 >> /sys/class/backlight/intel_backlight/brightness");
}
 
void MainWindow::on_pushButton_6_clicked()
{
    system("echo 2928 >> /sys/class/backlight/intel_backlight/brightness");
}
 
void MainWindow::on_pushButton_7_clicked()
{
    system("echo 3416 >> /sys/class/backlight/intel_backlight/brightness");
}
 
void MainWindow::on_pushButton_8_clicked()
{
    system("echo 3904 >> /sys/class/backlight/intel_backlight/brightness");
}
 
void MainWindow::on_pushButton_9_clicked()
{
    system("echo 4392 >> /sys/class/backlight/intel_backlight/brightness");
}
 
void MainWindow::on_pushButton_10_clicked()
{
    system("echo 4880 >> /sys/class/backlight/intel_backlight/brightness");
}
 
void MainWindow::on_pushButton_11_clicked()
{
    system("echo 0 >> /sys/devices/platform/asus-nb-wmi/leds/asus\:\:kbd_backlight/brightness");
}
 
void MainWindow::on_pushButton_12_clicked()
{
    system("echo 1 >> /sys/devices/platform/asus-nb-wmi/leds/asus\:\:kbd_backlight/brightness");
}
 
void MainWindow::on_pushButton_13_clicked()
{
    system("echo 2 >> /sys/devices/platform/asus-nb-wmi/leds/asus\:\:kbd_backlight/brightness");
}
 
void MainWindow::on_pushButton_14_clicked()
{
    system("echo 3 >> /sys/devices/platform/asus-nb-wmi/leds/asus\:\:kbd_backlight/brightness");
}
 
void MainWindow::on_pushButton_15_clicked()
{
    system("echo 122 >> /sys/class/backlight/intel_backlight/brightness");
}
mainwindow.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>89</width>
    <height>398</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralWidget">
   <widget class="QPushButton" name="pushButton">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>40</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>01</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_2">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>70</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>02</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_3">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>100</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>03</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_4">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>130</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>04</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_5">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>160</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>05</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_6">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>190</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>06</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_7">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>220</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>07</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_8">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>250</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>08</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_9">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>280</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>09</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_10">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>310</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>10</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_11">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>10</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>00</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_12">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>40</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>01</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_13">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>70</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>02</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_14">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>100</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>03</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_15">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>10</y>
      <width>31</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>00</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menuBar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>89</width>
     <height>30</height>
    </rect>
   </property>
  </widget>
  <widget class="QToolBar" name="mainToolBar">
   <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
   </attribute>
   <attribute name="toolBarBreak">
    <bool>false</bool>
   </attribute>
  </widget>
  <widget class="QStatusBar" name="statusBar"/>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections/>
</ui>

rusooo
()

RSS подписка на новые темы