(1) Get the value in TextEdit QString str = Ui->textedit->toplaintext (); This is the plain text p=str.toint (); Converts the value obtained from the TextEdit control to the Int type assignment to P
QString str = ui->textedit->tohtml (); This is rich text, that is, gets the HTML string
If the text is set, the corresponding is:
Ui->textedit->setplaintext ("123");
Ui->textedit->sethtml ("<b>123</b>"); (2) Get the value in LineEdit, with textedit,label QString str = ui->lineedit->text () ui->lineedit->settext (QString:: Number (level)); Displays a single digital ui->lineedit->settext ("Hello World"); Display string helloworldstring str= "Hello"; ui->lineedit->settext (str); Display string does not use UI to get values (deprecated) qlineedit * pEdit;
QString txt = pedit->text (); (3) Qlabel label space problem Qlabel border setting: Using Setframestyle ()
such as: Label.setframestyle (Qframe::noframe); No border
or use the function Setframeshape ()
such as: Label.setframeshape (Qframe::noframe);
The border property can be viewed in the QT Help file enum Qframe::shape (4) about Win7 under the Shutdown Statement system ("shutdown-s\" \ ""); Shutdown-a Cancel shutdown
Shutdown-s shut down the machine
Shutdown-f forcibly shutting down the application
SHUTDOWN-M \ \ computer name control remote computer
SHUTDOWN-I Displays the remote shutdown graphical user interface, but must be the first parameter of shutdown
Shutdown-l Log off the current user
Shutdown-r Shutdown and restart
Shutdown-s-T time setting shutdown countdown
Shutdown-h Hibernate (5) Modify the name Dialog Dialog at the top of the Dialog window;
Dialog.setwindowtitle ("new title"); What to fill in to change what
Dialog.show (); (6) Modify the icon of the dialog window icon with the application
First, prepare an ICO icon, for example: App.ico
The online icon files are generally in PNG format, where a website is recommended to convert other image formats such as PNG to ICO. and converted to the icon can choose a variety of size size.
http://www.converticon.com/
1. Generate the Makefile implementation process via Qmake:
A. Find a picture. ico, name changed to App.ico;
B. Create a new text document. txt, add internal idi_icon1 ICON discardable "App.ico" and rename the file to app.rc;
C. At the end of the App.pro file add rc_file = app.rc, after regeneration, the modification succeeds//note that the. rc file must be the same directory as the. exe
2. Do not qmake generate makefile implementation process:
As in the previous two steps, the last step is to load the. rc file into the project, right-click the project-add-existing file, add right-click. rc file compile, rebuild the executable and modify it successfully
(7) Qt window operation (must be placed in the constructor) for example, in the dialog window operation, we must put in the dialog window, variable initialization is the same
Setwindowflags (Qt::windowclosebuttonhint | Qt::D ialog); Turn off the other buttons for dialog
Setwindowflags (Qt::framelesswindoswhint | Qt::D ialog); No border, for Dialog
Setwindowflags (Windowflags () | Qt::windominimizebuttonhint); Add Minimized button
suppress the Maximize and minimize buttons at the same time
Qt::windowminmaxbuttonshint
It is also forbidden to close
W.setwindowflags (W.windowflags () &~ (Qt::windowminmaxbuttonshint | Qt::windowclosebuttonhint));
qt Full Screen display function
1, Window.showfullscreen ()//This method is only valid for the top-level window, the child window is invalid
QT maximized display function window.showmaximized ()
QT Minimized display function window.showminimized ()
QT fixed size display function window.resize (x, y)
Get screen width and height
Qapplication::d esktop ()->width ();
Qapplication::d esktop ()->height ();
(8) window transparency (put into a constructor function)
1. Qpalette Pal=palette ();
Pal.setcolor (Qpalette::background,qcolor (0x00,0xff,0xff,0x00));
SetPalette (PAL);
2 Setstylesheet ("Border:1px;backgrond: (0x00,0xff,0x00,0x00)");
(9) Use of the timer Qtimer (constructor function start)
Qtimer *timer=new Qtimer (this);
Connect (timer,signal () (timeout ()), This,slot (timerupdate)); Timerupdate define a custom signal slot as private slot:
Timer->start (1000); 1000ms = 1s
(10) Qtime Class Acquisition Time
Qtime current_time = Qtime::currenttime (); Get the exact time, define a Qtime class, the object is Current_time callable hour () function and minute function
hour = Current_time.hour ();
minute = Current_time.minute ();
Qdatetime time =qdatetime::currentdatetime (); Get the time of the system now
QString str = time.tostring ("Yyyy-mm-dd hh:mm:ss dddd"); Set display format year-month-day time: minute: Second week x Force the Qdatetime class into the Qstring class
Ui->label->settext (str);
Resources from Baidu, if you need to reprint please indicate the source
A little bit of knowledge about QT5 UI design