QT Version Music player

Source: Internet
Author: User
Tags line editor qt designer

QT Version Music player

Reprint please indicate the source: Muni column http://blog.csdn.net/u012027907

first, about QT

1.1 What is QT

QT is a cross-platform application and UI development framework. Using QT is a one-time development of applications that can be deployed across different desktop and embedded operating systems without rewriting the source code.

Qt Creator is a new cross-platform Qt IDE that can be used alone or in a complete set of SDKs with QT libraries and development tools, including: Advanced C + + code Editor, project and integration management tools, integrated context-sensitive Help system, graphical debugger, code management and browsing tools.

features of 1.2 qt

1) Intuitive C + + class Library: the modular qt C + + Class library provides a rich set of application building blocks that contain all the functionality required to build advanced cross-platform applications. With intuitive, easy to learn, easy to use, generate good understanding, easy to maintain code and so on.

2) portability across desktop and embedded operating systems : With QT, you can deploy across different desktop and embedded operating systems without the need to re-write code, so that QT is ubiquitous, with the ability to develop applications at once.

3) Use a single source code to locate multiple operating systems.

4) You can reallocate development resources without considering the platform.

5) code is not subject to long-term concerns about the impact of platform changes.

6) Integrated development tools with cross-platform IDE: Qt Creator is a cross-platform integrated development Environment (IDE) specifically tailored to meet the needs of QT developers. Qt Creator can run on Windows, linux/x11, and Mac OS X desktop operating systems, and public developers create applications for multiple desktop and mobile platform devices.

functions and characteristics of 1.3 Qt creator

1) Complex Code Editor: The Advanced Code Editor for Qt Creator supports C + + and QML (JavaScript), context-sensitive Help, code completion, native code conversion, and its functions.

2) Version control: support includes git, Subversion, CVS and other versioning.

3) Integrated user interface Designer: QT Creator provides two integrated visual editors: QT Designer for the Qwidget generation interface, and QT Quick Designer for developing dynamic interfaces through the QML language

4) Project and compile management: Qt Creator can generate the necessary files whether you are importing an existing project or creating a new project. Includes support for Cross-qmake and CMake.

5) Desktop and mobile platforms: supports compiling and running QT programs on desktop and mobile devices.

6) Qt Simulator: The QT Simulator is part of the Nokia Qt SDK.


Second, the window parts

2.1 Basic Widget Qwidget

The Qwidget class is the base class for all user-interface objects, called the Base window part. Qwidget inherits from the Qobject class and the Qpaintdevice class, where the Qobject class is the base class for all the Qt object models that support it, and the Qpaintdevice class is the base class for all objects that can be drawn.

2.2 dialog box Qdialog

dialog boxes are divided into modal dialogs and non-modal dialog boxes.

Modal dialog box: You cannot interact with other windows of other applications until the dialog box is closed. A common modal dialog box is a prompt dialog box and a warning dialog box.

Non-modal dialog box: In contrast to modal dialogs, you can interact with other windows of other applications before they are closed.

2.2.1 Recognize signals and slots

Using the signal and slot mechanism in QT to accomplish the cooperative operation between objects, simply speaking, signals and slots are functions, such as clicking a button on a window to pop up a dialog box, then you can associate the button's click signal with the defined slot, where you can create a dialog box and display it. Click this button to launch a signal and then execute the slot to display a dialog box.

2.2.2 Standard dialog box

Common standard dialog boxes are: Color dialog box, file dialog box, Font dialog box, Input dialog box, message dialog box, progress dialog box, Error message Dialog Box, Wizard dialog box.

2.3 Other widgets

2.3.1 Qframe Class

The Qfame class is the base class for a part with a border, and its subclasses have the most common label parts Qlabel, Qlcdnumber, Qsplitter, Qstackedwidget, Qtoolbox, and Qabstractscrollarea classes.

2.3.2 Button Assembly

The Qabstractbutton class is an abstract class of button parts that provides the general functionality of a button. Its subclasses include check boxes Qcheckbox, Standard button Qpushbutton, radio button Qradiobutton, and Tool button Qtoolbutton.

2.3.3 Line Editor

The Line editor Qlineedit part is a single-line text editor that allows users to enter and edit plain text content of a single line, and provides a range of useful features, including undo and redo, cut and drag-and-drop operations.

2.3.4 Value Setting box

The Qabstractspinbox class is an abstract class that provides a numeric setting box and a row editor to display the set value. It has three subcategories of Qdatetimeedit, Qspinbox, and Qdoublespinbox, respectively, to complete the setting of DateTime, Integer, and floating-point numbers.

2.3.5 Slider Parts

The Qabstractslider class provides an integer value within a range, with a slider that can be positioned to any value of an integer interval. This class is an abstract class with 3 subclasses of Qscrollbar, Qslider, and qdial. The scroll bar Qscrollbar is used more in the Qscrollarea class to implement the scrolling area, while Qslider is the most common slider for volume control or multimedia playback progress, and qdial is a scale dial.

third, layout management3.1 Layout Management system

QT's layout management system provides a simple and powerful mechanism to automatically arrange parts in a window to ensure that they use space effectively. QT includes a set of layout management classes that describe how to lay out parts in the user interface of an application. For example, several subclasses of Qlayout, which they call the layout manager. All instances or objects of subclasses of the Qwidget class can use the layout manager to manage the child parts in which the Qwidget::setlayout () function can apply the layout manager on a part. Once the layout manager is set up on a part, it will do several things:

* Positioning sub-parts

* Perceived window default size

* Minimum perceived window size

* Change size handling

* Updated automatically when content changes

The layout manager has:

1) Basic Layout Manager (Qboxlayout)

2) Raster Layout Manager (Qgridlayout)

3) Form Layout Manager (Qformlayout)

The qslider is a very useful thing, he provides the layout manager's splitting function, can divide a part evenly.

3.2 Setting up partnerships

By setting a label and an input box as a partnership, you can make the two a partnership.

3.3 Setting the tab order

Use the Settaborder () function to set the order of the TAB keys.

iv. Application main window4.1 main window frame

The main window provides a framework for building the application user interface, and QT provides Qmainwindow and other related classes together to form the main window. The Qmainwindow class has its own layout. It contains parts:

1) Menu bar: The menu contains a list of drop-down menu items that are implemented by the Qaction action class. The menu is at the top of the main window, and a main window can have only one menu bar.

2) Toolbars: toolbars are typically used to display some commonly used menu items, or to insert other widgets, and toolbars can be moved. A window can control multiple toolbars.

3) Central part: in the center of the window can be placed in a window part as a central part, is the application of the main functional implementation area. A main window can have only one central part.

4) Dock parts: Dock parts are often referred to as docking windows because they can be docked for four weeks in a central part. It is used to place some parts to implement some functions, like a toolbox. A main window can have multiple dock parts.

5) Status bar: The status bar is used to display some program status information at the bottom of the main window. A main window can have only one status bar.

4.2 Rich Text processing

Rich text is the ability to use multiple formats in a document, such as font colors, pictures, and tables. It is relative to the plain text (Plain text). For example, Notepad on Windows is a plain text editor, and Word is a rich text editor. QT provides support for rich text processing, and you can see the rich-text processsing keyword in Help.

The structure of a rich text document:

qtextedit:a.qtextcursor retrieves Qtextframeformat, Qtextblockformat, qtexttable, Qtextlistformat

B.qtextdocument retrieving Qtextframe, Qtextblock, qtexttable, qtextlist

4.3 Drag-and-drop operations

For an application, not only will you want to open a file from the File menu, but you can simply drag a file from the desktop into the program interface to open it, just as you can drag the. Pro file into the QT creator to open the entire project. QT provides powerful drag-and-drop operations that can be seen in the Help for drag and drop keywords. Drag-and-drop operations are divided into two operations: drag (Drag) and (drop). When data is dragged, it is stored as a MIME type, the Qmimedata class is used in Qt to represent the MIME type of data, and the Qdrag class is used to complete the transfer of data, while the entire drag-and-drop operation defines what I am doing in several mouse events and drag-and-drop events.

v. Event System5.1 events in QT

An event is a generic term for what a variety of applications need to know about things or actions generated internally or externally by an application. In Qt, an object is used to represent an event that inherits from the Qevent class. It is necessary to note that the event is not the same as the signal, such as clicking a button on an interface, then the mouse event qmouseevent (not the button generated), but because the button is pressed, it emits a clicked () Click Signal. This only cares about the button's click Signal, regardless of the mouse event, but if you want to design a button, or when you click the button to have other effects, then you should be concerned about mouse events.

There are 5 ways to handle events in the Help documentation for the Notify () function of the Qcoreapplication class:

Method One: Re-implement the PaintEvent (), Mousepressevent () and other event handler functions of the part. This is the most common method, but it can only be used to handle specific events for a particular part.

Method Two: Re-implement the Notify () function. This function is powerful and provides complete control, which can be obtained before event filters get events. However, it can only handle one event at a time.

Method Three: Re-implement the event () function. The event () function of the Qobject class can obtain an event before it reaches the default event handler function.

Method Four: Install the event filter on the item Qapplication object. Because a program has only one Qapplication object, this implementation is the same as using the Notify () function, with the advantage that multiple events can be handled at the same time.

Method Five: Install the event filter on the object. You can use event filters to handle different events for different subassemblies in one interface class at the same time.

5.2 Mouse events and wheel events

The Qmouseevent class is used to represent a mouse event that produces mouse events when the mouse is pressed or the mouse pointer is moved in the widget. Using the Qmouseevent class, you can tell which key is pressed, the current position of the mouse pointer, and so on. It is often a matter of redefining a part's mouse event handlers to do some custom actions.

The Qwheelevent class is used to represent mouse wheel events, in which the main thing is to get the direction and distance of the wheel movement. To perform the appropriate operation.

5.3 Keyboard Events

Qkeyevent is used to describe a keyboard event.     When the keyboard is pressed or released, the keyboard event is sent to the part that has the keyboard input focus. The key () function of qkeyevent can get specific keys, and for all keys given in Qt, you can view the Qt::key keyword in Help. In particular, the ENTER key is Qt::key_return, and some modifier keys on the keyboard are not as good as the CTRL and SHIFT keys, which need to be obtained using the qkeyevent modifiers () function.

5.4 Timer events and random numbers

The Qtimerevent class is used to describe a timed event. For a subclass of Qobject, you only need to use the int qobject::starttimer (intinterval) function to turn on a timer, and this function needs to enter an integer in milliseconds as the parameter to indicate the set time. He returns an integer number to represent the timer. When the timer overflows, it is possible to get the number of the timer in the TimerEvent () function for related operation.

For random numbers, the Qrand () Han Qsrand () Two functions are used in QT.

5.5 Sending of event filters and events

QT provides event filters to monitor the events of multiple other parts in one part. Unlike other parts, an event filter is not a class, but an operation consisting of two functions that is used to monitor the event of one part to another. These two functions are installeventfilter () and EventFilter () respectively, and the part is a function in the Qobject class.

Vi. appearance of the interface6.1 qt Style

The various styles in QT are a set of classes that inherit from Qstyle. The Qstyle class is an abstract base class that has a GUI in it, and Qt's built-in (built-in) parts use it to perform almost all of the drawing work to make sure that they look like local parts on each platform. Some of the styles have been built into QT.

The styles offered by QT are:

1) Qcdestyle: CDE Style

2) Qcleanlooksstyle: similar to Gnome's clearlook style

3) Qmacstyle: Mac OS Style

4) Qmotifstyle: motif Style

5) Qwindowsstyle: Microsoft Windows style

6.2 qt Style sheet

A QT style sheet is a very powerful mechanism for customizing the appearance of a part. The concept, terminology, and syntax of the QT stylesheet are inspired by the HTML cascading style sheet (CSS), but unlike CSS, the QT style sheet is applied to the world of widgets.

6.3 Special Effects form

Forms that can implement special effects such as irregular forms, transparent forms, and so on, can make the application look more personal and appealing.

Reprint please indicate the source: Muni column http://blog.csdn.net/u012027907

Vii. Examples of music players7.1 Functional Requirements

1) Import music files and folders

2) Play, pause, previous, Next and stop functions

3) display and lyrics display of playlist

4) control of sound size and progress

5) display of the spectrum

6) Beautiful interface design

7.2 Overall Design

1) interface design:

Mainly play list, spectrum display, play, pause and other button design, interface design I spent a lot of effort to design a beautiful interface, but also benefit from the QT designer, using a CSS-like approach to the design of the interface, so that the interface can easily change.

2) Import music files, play, pause and other functional design:

Import file using the File dialog box, play, pause directly using the Qmediaplayer class of function control, import folder is a difficult point, mainly in the scan folder under all the files, Extract the. mp3 type of file, and then add it to the Qmediaplaylist list class, then write its playback path to the file and then read it into the playlist and display it.

3) Design of lyrics playback class:

The lyrics play form and playback function are designed separately.

4) Spectrum display:

The specific classes of the spectrum display are also individually designed and displayed when displayed in the main form.

7.3 Technical Difficulties

The technical difficulty of music player is the display of lyrics and spectrum. First of all, the overall idea of the lyrics play is to get the current music playback time progress, and then compared with the lyrics file point in time, if the point of time, then play back the lyrics, get the time and the next line of lyrics, evenly play can, followed by the spectrum of the display, this relatively difficult, I refer to the sample program that comes with QT, which is the Fourier transform of the music file, then obtains the values of the different frequency bands, and finally shows the dynamic. I use the Qmediaplayer class and the Qmeidaplaylist class for playing music, not with the phonon framework, because Qt5.0 no longer uses the multimedia framework.

7.4 Test Implementation

Reprint Please indicate the source: Muni column http://blog.csdn.net/u012027907



QT Version Music player

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.