customizing Widgets--custom Widgets

Source: Internet
Author: User

By means of inheritance, subclasses of the original widgets

(1) Improvement Method (Promotion): Create a new project, drag the Qspinbox part into the form in the UI interface, right-click the part. In the pop-up menu, select Promote to. ( Add the following two files to the project )

#ifndef Hexspinbox_h#defineHexspinbox_h#include<QSpinBox>classQregexpvalidator;classHexspinbox: Publicqspinbox{Q_object Public: Hexspinbox (Qwidget*parent);protected: Qvalidator::state Validate (QString&text,int&pos)Const; intValuefromtext (ConstQString &text)Const; QString Textfromvalue (intValConst;Private: Qregexpvalidator*Validator;};#endif //Hexspinbox_h

#include <QtGui>#include"HexSpinBox.h"Hexspinbox::hexspinbox (Qwidget*parent): Qspinbox (parent) {SetRange (0,255);//default range of inputValidator=NewQregexpvalidator (Qregexp ("[0-9a-fa-f]{1,8}"), This);//Accept 1 to 8 characters}qvalidator::state hexspinbox::validate (QString&text,int&pos)Const{    returnValidator->validate (Text,pos);//Check that the input is legal}qstring Hexspinbox::textfromvalue (intValConst{    returnQstring::number (Val, -). ToUpper ();//convert integers to Strings to update spinner boxes}intHexspinbox::valuefromtext (ConstQString &text)Const{    BOOLOK; returnText.toint (&ok, -);//if the string is not a valid hexadecimal number: OK is false;}

  

(2) Plug-in method (plugin)

customizing Widgets--custom Widgets

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.