[QT] UI beautification [updated on] (reproduced)

Source: Internet
Author: User

-Experience Summary

1. The available dialog box (qdialog) simulates the effect similar to the toast in Android.

    -Set the program interface style

In the main function
Qapplication: setstyle ("Windows ");
Qapplication: setstyle ("WindowsXP ");
Qapplication: setstyle ("motif ");
Qapplication: setstyle ("CDE ");
Qapplication: setstyle ("Macintosh ");
Qapplication: setstyle ("Plastique ");

The style can be "Windows", "motif", "CDE", "Plastique", "WindowsXP", "Macintosh"
    -Set window styles

Setwindowflags (flags)

Flags:
Qt: windowcontexthelpbuttonhint
Qt: framelesswindowhint // remove the title bar
Qt: customizewindowhint
Qt: windowtitlehint // only has the title bar and no window control button
Qt: windowsystemmenuhint
Qt: windowclosebuttonhint
Qt: windowmaximizebuttonhint
Qt: windowminimizebuttonhint
Qt: subwindow
Qt: Desktop
Qt: splashscreen
Qt: tooltip
Qt: Tool

// No title bar icon, no buttons, only title
Qt: customizewindowhint | QT: windowtitlehint

Usage 1:
Clientmainwindow: clientmainwindow (qwidget * parent ):
Qmainwindow (parent, QT: windowclosebuttonhint)
{
...
}

Usage 2:
Clientmainwindow: clientmainwindow (qwidget * parent ):
Qmainwindow (parent)
{
...
This-> setwindowflags (QT: windowclosebuttonhint );
...
}
-The window is displayed in the center of the screen.

# Include <q1_topwidget>

Method 1:
W. Move (qapplication: desktop ()-> width ()-W. Width ()/2,
(Qapplication: desktop ()-> height ()-W. Height ()/2 );

Method 2:
Q1_topwidget * desktop = qapplication: desktop (); // = qapp-> desktop ()
W. move (desktop-> width ()-This-> width ()/2, (desktop-> height ()-This-> height ()/2 ); note: W is a QT window object (such as qmainwindow and qdialog)   -Modify the starting position of the UI program on the desktop

Add the following code to the program:
W. move (x, y); // the upper left corner of the screen is (0, 0), and X and Y are relative to (0, 0) the offset value of // W is the QT window object (such as qmainwindow and qdialog)   -Remove the icon on the left of the title bar.

1. Create a transparent icon
Use Photoshop to create a transparent icon
Reference settings: Size: 1x1 px
Name: logo.png

2. Add the icon to the Project
1) create an external reso.directory under the project directory and copy logo.png to this directory.
2) Add a resource file in the project named "icon. qrc"
3) Upload a prefix in icon.qrc(this is a temporary reseller. Add a file in the prefix to logo.png.
4) set a name for logo.png (this parameter is the same as the file name, that is, “logo.png ")
Note: aliases are used for engineering calls.

3. Set the window icon
Qwidget. setjavaswicon (qicon (": Res/logo.png "));
Note: The upload reseller is the prefix of the resource file (.qrc.pdf, And the upload logo.png is the alias of logo.png. Do not omit the preceding ":"

4. Test
After completing the above operations, re-build the project and execute it to see the effect   -Mouse pointer

1. Hide pointer
# Include <qwsserver>
...
Qwsserver: setcursorvisible (false); // Add it to the constructor of mainwindow. 2. Set the pointer style.
Qapplication: setoverridecursor (QT: waitcursor); // set the pointer to the waiting state (funnel-like)
Qapplication: restoreoverridecursor (); // restores the mouse pointer to the default value.
    -Modify the widget Style
1. qlabelui-> label-> settext ("<B> <font color = blue size = 30> test! </Font> </B> "); // modify the qlabel text style UI-> label-> setpixmap (qpixmap (": Res/logo_png ")); // display image UI-> label-> setscaledcontents (true); // adjust the image label size (called before the image is displayed) UI-> label-> setwordwrap (true ); // automatic line feed (effective premise: the content contains Chinese characters or separators, such as spaces) 2. qlineedit
// No border, transparent background
UI-> lineedit-> setstylesheet ("qlineedit {border-width: 0; border-style: outset}"); 3. qpushbuttonui-> Pb-> setstylesheet ("Background: Red"); // change the qpushbutton color
* Other available colors include yellow, blue, green, black, and white. 4. qdockwidget
Qwidget * titlewidget = new qwidget (this );
UI-> dockwidget-> settitlebarwidget (titlewidget); // hide the title bar

! Clear all styles
UI-> Pb-> setstylesheet (""); orui-> Pb-> stylesheet (). Clear ();! Remove the control focus widget-> setfocuspolicy (QT: nofocus );

-Translucent form

1. Create a translucent background image (PNG format to adjust the transparency)
2. Add the following code:
This-> move (0, 0); // locate the position displayed on the form
This-> setwindowflags (QT: framelesswindowhint); // The format style must be set.
This-> setattribute (QT: wa_translucentbackground); // you can specify the "transparent background" attribute.

Note: if you cannot set the form to the QT: framelesswindowhint style using the preceding method, try the following methods:
Bnumpad: bnumpad (qwidget * parent ):
Qdialog (parent, QT: framelesswindowhint ),
UI (new UI: bnumpad)
{
...
}


-Display icons in the text box

1. Use a qframe/qlabel to display the icon and place it above qlineedit.
2. Set the qlineedit attribute.
UI-> lineedit-> settextmargins (21, 0, 0, 0); // set the icon to the left of qlineedit


-Startup interface Example

# Include <qtgui/qapplication>
# Include <qsplashscreen>
# Include <qtimer>
# Include "mainwindow. H"

Int main (INT argc, char * argv [])
{
Qapplication A (argc, argv );
Mainwindow W;

Qpixmap pixmap (": Res/BG ");
Qsplashscreen splash (pixmap );
Splash. Show ();

Qtimer: singleshot (1500, & splash, slot (hide ()));
Qtimer: singleshot (2000, & W, slot (show ()));

Return a.exe C ();
}

[QT] UI beautification [updated on] (reproduced)

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.