Qt widgets--Abstract slider and its inheriting class

Source: Internet
Author: User
Tags list of attributes

The default appearance of the three visual classes is as follows (Win7): Their sliders are at the minimum value of 0.

When you understand Qabstractslider

You can think of it as accomplishment is Qscrollbar (the widget's appearance has more than one Qabstractslider attribute):

The list of attributes is as follows:

  • Invertedappearance:bool appearance upside down
  • Invertedcontrols:bool control Upside down
  • Maximum:int Maximum Value
  • Minimum:int Minimum value
  • Orientation: facing (horizontal or vertical) qt::orientation
  • Pagestep:int, click on the "slot" (not the slider and arrow) at the time of the change value
  • Singlestep:int Single Step value, click on the scroll bar arrows when changing the value
  • Sliderdown:bool
  • Sliderposition:int Slider Position
  • Tracking:bool tracking, the signal is sent in a different way
  • Value:int the current slider value

The default values when not being set are as follows:

The public function is mainly to assign or value the above attribute, the list is as follows: (with the horizontal scroll bar (the upper right corner of the figure) description)

Qabstractslider (qwidget * parent =0)  ~Qabstractslider ()//basic use, you need to set the followingvoidSetminimum (int)//the value that the slider represents when it is at the leftmost endvoidSetmaximum (int)//the value that the slider represents when it is at the very right endvoidSetsinglestep (int)//the length of the slider changes when you click the left or right small arrowvoidSetpagestep (int)  voidSetsliderposition (int)//set the position after the slider is initialized//Special requirements, you need to set the followingvoidSettracking (BOOLEnable//set whether to track, by default true, when tracking, as long as the slider value is changing, it constantly sends a signal (more times), false, only when the loosening of the slider value changes only issued (less times) specific test examples of outputvoidSetinvertedappearance (BOOL)//when set to True, the maximum minimum position is swapped, and when you click the arrow, the slider goes in the opposite directionvoidSetinvertedcontrols (BOOL)  voidSetsliderdown (BOOL)  //The following retrieval values, most of which correspond to the aboveintValue ()Const  intMaximum ()Const  intMinimum ()Const  intSingleStep ()Const  intPagestep ()Const  intSliderposition ()Const    BOOLHastracking ()Const  BOOLInvertedappearance ()Const  BOOLInvertedcontrols ()Const  BOOLIssliderdown ()Const    voidtriggeraction (slideraction action) qt::orientation Orientation ()Const  

The public slot functions are as follows:

void    SetOrientation (qt::orientation)// code creation By default is vertical, requires landscape can be set this, the enumeration value in the lower   void    SetRange (intint max)// Set value in the range of variation, same   as Setminimun and Setmaxmun two function void    setValue (int)  

Enum Qt::orientation:

Constant    Value  qt::horizontal  0x1  qt::vertical    0x2  

The signal is as follows:

void    actiontriggered (int  action)  void    rangechanged (intint  Max)  void    slidermoved (int  value)  void     sliderpressed ()   void     sliderreleased ()  void    valuechanged (int value)// generally use this  
——————————————————————————————————————————————————————

Qscrollbar most functions inherit from the above class,

Its public function has only constructors:

0 )  0)  ~qscrollbar ()  

Examples are as follows:

#include"dialog.h"#include"ui_dialog.h"#include<QGridLayout>#include<QScrollBar>#include<QDebug>Dialog::D ialog (Qwidget*parent): Qdialog (parent), UI (NewUi::D ialog) {UI-&GT;SETUPUI ( This); ScrollBar=NewQscrollbar; ScrollBar->setminimum (5); ScrollBar->setmaximum ( -); ScrollBar->setsinglestep (2); ScrollBar->setpagestep (5); ScrollBar->setsliderposition (Ten); ScrollBar->setorientation (qt::horizontal);//change it to a horizontal//scrollbar->setinvertedappearance (TRUE); //Scrollbar->setinvertedcontrols (TRUE); //scrollbar->settracking (FALSE); Qgridlayout*layout =NewQgridlayout;//layout class for displaying parts to the built-in UILayout->addwidget (ScrollBar,0,0);        SetLayout (Layout); Connect (scrollbar,signal (valuechanged (int)), This, SLOT (Sb_value_changed (int)));//connect the signal, the value of the output of a change} Dialog::~Dialog () {DeleteUI; }    voidDialog::sb_value_changed (inta) {Qdebug ()<<A; }  

————————————————————————————————————————————————————————————

Compared to Qslider,

More Tick (mark, translated into a good scale), it adds a tick at both ends of the centerline to mark the value.

The public functions are as follows:

<span style="White-space:pre"> </span>qslider (qwidget * parent =0)  <span style="White-space:pre"> </span>qslider (qt::orientation Orientation, qwidget * parent =0)  <span style="White-space:pre"> </span>~Qslider ()voidSettickinterval (intTi//set the scale intervalvoidSettickposition (tickposition position)//tick position, enumeration value, see belowintTickinterval ()Consttickposition tickposition ()Const  

enumeration value for tick position enum Qslider::tickposition

Qslider::noticks 0 No scale, default
Qslider::ticksbothsides 3 Draw at both ends of midline
Qslider::ticksabove 1 Draw the top of the line
Qslider::ticksbelow 2 Below the line
Qslider::ticksleft Ticksabove Line left
Qslider::ticksright Ticksbelow Line right

After setting the scale chart:

Code:

slider=new  Qslider;  Slider--setorientation (qt::horizontal);  Slider--settickposition (qslider::ticksabove);  Slider->settickinterval (5);  

Other commonly used functions and signals are derived from abstract classes, which do not dwell on
————————————————————————————————————————————————————————————

Qdial is similar to Qslider and also has a notch (nicks) concept.

The public functions are as follows:

0 )  ~qdial ()  intconst  qreal    const  BOOL    Const  void    Setnotchtarget (double target)//notch target refers to the pixel distance between two ticks, the  default 3.7pxbool     Const  

Public Slots:

void    Setnotchesvisible (bool visible)// Set if the nicks are visible,  void setwrapping is not visible by default     ( bool on)  

Wrap has a winding, coiled meaning that can be understood as the end-to-end phase, set to True (left) and not set to false effects, respectively, as follows:

Qt widgets--Abstract slider and its inheriting class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.