Qt and qt music players

Source: Internet
Author: User
Tags line editor qt designer

Qt and qt music players

Qt music player

Reprinted please indicate the source: dunni column http://blog.csdn.net/u012027907

I. Qt

1.1 What is Qt

Qt is a cross-platform application and UI development framework. With Qt, you can deploy applications across different desktops and embedded operating systems without having to rewrite the source code.

Qt Creator is a brand new cross-platform Qt IDE that can be used independently. It can also be used together with the Qt library and development tools to form a complete SDK, including: Advanced C ++ code editor, project and integration management tools, integrated context-related help systems, graphical debuggers, and code management and browsing tools.

1.2 features of Qt

1) intuitive C ++ Class Library:The modular Qt C ++ Class Library provides a rich set of Application Generation blocks, including all the functions required by the component advanced cross-platform application. It is intuitive, easy to learn, easy to use, and generates easy-to-understand and easy-to-maintain code.

2) portability across desktops and Embedded Operating Systems: With Qt, you only need to develop an application at a time to deploy it across different desktop and embedded operating systems without re-writing code. It can be said that Qt is everywhere.

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

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

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

6) integrated development tools with cross-platform IDE:Qt Creator is a cross-platform integrated development environment (IDE) tailored to meet the needs of Qt developers ). Qt Creator can be run on Windows, Linux/X11, and Mac OS X desktop operating systems. Open senders can create applications for multiple desktop and mobile platform devices.

1.3 functions and features of Qt Creator

1) complex code editor:The advanced code editor of Qt Creator supports C ++ and QML (JavaScript), context-related help, code success, native code conversion, and functions.

2) Version Control:Supports version control including Git, Subversion, and CVS.

3) Integrated User Interface Designer:Qt Creator provides two integrated visual Editors: Qt Designer used to generate interfaces through QWidget and Qt Quick Designer used to develop dynamic interfaces through QML language.

4) project and compilation management:Qt Creator can generate necessary files whether to import the original project or create a new project. Including support for Cross-qmake and Cmake.

5) desktop and mobile platforms:Supports compiling and running Qt programs on desktops and mobile devices.

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


Ii. window components

2.1 Basic widget

The QWidget class is the base class of all user interface objects and is called the basic window component. QWidget inherits from the QObject class and QPaintDevice class. QObject class is the base class that supports the Qt object model. QPaintDevice class is the base class of all objects that can be drawn.

2.2 dialog box QDialog

The dialog box is divided into modal dialog box and non-modal dialog box.

Modal Dialog Box: you cannot interact with other windows of other applications before the dialog box is closed. Common modal dialogs are prompt and warning dialogs.

Non-Modal Dialog Box: Unlike the modal dialog box, it can interact with other windows of other applications before it is closed.

2.2.1 recognition signals and slots

In Qt, the signal and slot mechanisms are used to complete the collaborative operations between objects. In short, both signals and slots are functions. For example, you can click a button in the window to bring up a dialog box, then you can associate the click signal of this button with the defined slot. In this slot, you can create a dialog box and display it. In this way, click this button to initiate a signal, and then execute the slot to display a dialog box.

2.2.2 standard dialog box

Common standard dialogs include the color dialog box, file dialog box, font dialog box, input dialog box, message dialog box, progress dialog box, error message dialog box, And wizard dialog box.

2.3 other Widgets

2.3.1 QFrame class

A border ame class is a base class with borders. Its subclasses include the most common label components, such as QLabel, QLCDNumber, QSplitter, QStackedWidget, QToolBox, and qw.actscrollarea.

2.3.2 button parts

The qiniactbutton class is an abstract class for button components and provides common functions for buttons. Its sub-classes include check box QCheckBox, standard button QPushButton, single-choice button QRadioButton, and tool button QToolButton.

2.3.3 Line Editor

The QLineEdit component of the row editor is a single-line text editor that allows users to enter and edit the plain text content of a single row. It also provides a series of useful functions, the options include undo and restore, cut, and drag-and-drop.

2.3.4 Value Setting box

The qiniactspinbox class is an abstract class that provides a Value Setting box and a row editor to display the set value. It has three sub-classes: QDateTimeEdit, QSpinBox, and QDoubleSpinBox, which are used to set the date and time, integer, and floating point respectively.

2.3.5 slider parts

The qiniactslider class provides an integer value in a range. It has a slider to locate any value in an integer range. This class is an abstract class with three sub-classes QScrollBar, QSlider, and QDial. Among them, the scroll bar QScrollBar is more used in the QScrollArea class to implement the rolling area. The QSlider is the most common slider for volume control or multimedia playback progress, and the QDial is a dial.

Iii. layout management 3.1 Layout Management System

The layout management system of Qt provides a simple and powerful mechanism to automatically Arrange parts in a window to ensure that they can use space effectively. Qt includes a set of layout management classes to describe how to layout parts on the application's user interface. For example, the sub-classes of QLayout are called layout manager. You can use the layout manager to manage child widgets of all instances or objects of the QWidget class. The QWidget: setLayout () function can apply the layout manager to a widget. Once a layout manager is set on a part, it performs the following operations:

* Positioning sub-Parts

* Default size of the perception window

* Minimum size of the sensing window

* Resize

* Automatically updated when the content changes

Layout manager:

1) basic layout manager (QBoxLayout)

2) grid layout manager (QGridLayout)

3) form layout manager (QFormLayout)

The splitter QSlider is a useful feature that provides the split function of the layout manager to split a component evenly.

3.2 set up partnerships

You can set a tag and an input box as a partnership to associate the two.

3.3 set the Tab key order

Use the setTabOrder () function to set the order of the Tab key.

4. Main Window framework of application 4.1

The main window provides a framework for creating the application user interface. Qt provides QMainWindow and other related classes to form the main window. The QMainWindow class has its own layout. It contains the following parts:

1) menu bar:A menu contains a list of drop-down menu items, which are implemented by the QAction items class. The menu is located at the top of the main window, and one main window can have only one menu bar.

2) toolbar:The toolbar is used to display some commonly used menu items, insert other window components, and move the toolbar. Multiple toolbar can be controlled in one window.

3) central components:You can place a widget in the center area of the window as the central component, which is the main function implementation Area of the application. One main window can only have one central part.

4) Dock parts:The Dock part is often called a Dock window because it can be docked around the center part. It is used to place some parts to implement some functions, just like a toolbox. A single main window can have multiple Dock parts.

5) status bar:The status bar displays the status information of some programs at the bottom of the main window. One main window can only have one status bar.

4.2 Rich Text Processing

Rich Text can be used in multiple formats, such as font colors, images, and tables. It is relative to Plain Text. For example, Notepad on Windows is a plain text editor, while Word is a rich text editor. Qt provides support for Rich Text Processing. You can view the Keyword Rich Text Processsing in the help section.

Structure of Rich Text documents:

QTextEdit: A. QtextCursor retrieves QTextFrameFormat, QTextBlockFormat, QTextTable, QTextListFormat

B. QTextDocument: retrieve QTextFrame, QTextBlock, QTextTable, and QTextList

4.3 Drag and Drop Operations

For an application, you not only want to open a file from the File menu, but also want to drag the file on the desktop directly into the program interface to open it, just as you can. the pro file is dragged into the Qt Creator to open the entire project. Qt provides powerful Drag-and-Drop operations, allowing you to view the Drag and Drop keywords in help. Drag and Drop Operations are divided into two types: Drag and Drop Operations. When data is dragged, it is stored as MIME type. In Qt, QMimeData class is used to represent MIME-type data, and QDrag class is used to transfer data, the entire drag-and-drop operation defines how many mouse events and drag-and-drop events are completed.

5. Events in Event System 5.1 Qt

An event is the general name of the events or actions that are generated inside or outside the application that various applications need to know. In Qt, an object is used to represent an event, which is inherited from the QEvent class. It should be noted that the event is different from the signal. For example, if you click a button on the interface, the mouse event QMouseEvent (not generated by the button) is generated, but the button is pressed, therefore, it sends a clicked () signal. Here, we only care about the click signal of the button, instead of the mouse event. But if you want to design a button or make it produce other effects when you click the button, you need to care about the mouse event.

Five event handling methods are provided in the help document of the notify () function of the QCoreApplication class:

Method 1: Re-implement the paintEvent (), mousePressEvent (), and other event processing functions of the component. This is the most common method, but it can only be used to handle specific events of specific parts.

Method 2: implement the notify () function again. This function is powerful and provides full control, which can be obtained before event filters get events. However, it can only process one event at a time.

Method 3: implement the event () function again. The event () function of the QObject class can obtain the event before the event reaches the default event processing function.

Method 4: Install the Event Filter on the QApplication object. Because a program has only one QApplication object, the functions implemented in this way are the same as those implemented using the Notify () function. The advantage is that it can process multiple events at the same time.

Method 5: Install the Event Filter on the object. You can use the Event Filter to process different events of different sub-parts simultaneously in an interface class.

5.2 mouse and scroll wheel events

The QMouseEvent class is used to represent a mouse event. A mouse event occurs when you press or move the mouse pointer in a widget. The QMouseEvent class can be used to obtain information about which key is pressed and the current position of the mouse pointer. Generally, the mouse event processing function of a part is redefined to perform some custom operations.

The QWheelEvent class is used to indicate the scroll wheel event. In this class, the direction and distance of the scroll wheel are obtained. To perform corresponding operations.

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 a part with the keyboard input focus. The key () function of QKeyEvent can obtain specific keys. For all keys specified in Qt, you can view the Qt: Key keyword in help. Note that the Enter key here is Qt: Key_Return; some modifier keys on the keyboard are not as good as Ctrl and Shift keys. Here we need to use the modifiers () of QKeyEvent () function.

 

5.4 timer events and random numbers

The QTimerEvent class is used to describe a scheduled event. For a subclass of A QObject, you only need to use the int QObject: startTimer (intinterval) function to enable a timer, this function requires an integer in milliseconds as the parameter to indicate the set time. It returns an integer number to represent this timer. When the timer overflows, you can obtain the number of the timer in the timerEvent () function to perform related operations.

The random number is implemented using the qrand () and qsrand () functions in Qt.

5.5 Event Filter and event sending

Qt provides an Event Filter to monitor events of multiple other components in one component. Unlike other components, the event filter is not a class, but an operation composed of two functions to monitor the events of other components. These two functions are installEventFilter () and eventFilter (), and the component is a function in the QObject class.

Vi. UI appearance 6.1 Qt Style

Various styles in Qt are a group of classes inherited from QStyle. The QStyle class is an abstract base class with a GUI appearance. The built-in component of Qt uses it to execute almost all the painting work, to make sure they look like local components on each platform. Some styles are built in Qt.

Qt provides the following styles:

1) QCDEStyle:CDE Style

2) QCleanlooksStyle:Similar to the Clearlook style of GNOME

3) QMacStyle:Mac OS Style

4) QMotifStyle:Motif Style

5) QWindowsStyle:Microsoft Windows style

6.2 Qt Style Sheets

Qt style sheets are powerful mechanisms for customizing the appearance of components. The concepts, terms, and syntax of Qt style sheets are all inspired by HTML Cascading Style Sheets (CSS). However, unlike CSS, Qt style sheets are applied in the world of components.

6.3 special effect form

You can implement irregular forms, transparent forms, and other special forms to make the appearance of applications more personalized and attractive.

Reprinted please indicate the source: dunni column http://blog.csdn.net/u012027907

VII. Functional requirements of music player instance 7.1

1) Import music files and folders

2) playback, pause, last song, next song, stop, and other functions

3) display the playlist and Its lyrics

4) Sound size and progress control

5) spectrum display

6) Beautiful Interface Design

7.2 Overall Design

1) Interface Design:

It mainly involves the design of the playback list, spectrum display, play, pause, and other buttons. I have spent a lot of time designing the interface to design a beautiful interface, and also benefited from the Qt designer, use CSS-like methods to design the interface, making it easy to change.

2) function design for importing music files, playing and pausing music files:

You can add the listener type file to the QMediaPlaylist class, write its playback path to the file, and then read it into the playlist and display it.

3) Design of the lyrics play class:

Design the lyrics playback form and playback function separately.

4) spectrum display:

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

7.3 technical difficulties

The technical difficulty of a music player is to play the lyrics and display the spectrum. First, the overall idea of playing the lyrics is to get the time progress of playing the current music, and then compare it with the time point of the lyrics file. If the time is reached, play the subsequent lyrics, the time difference between the time point and the next lyrics is obtained. It can be played evenly, followed by the display of the spectrum. This is relatively difficult. I have referred to the example program in Qt, it is to perform Fourier transformation on the music file, then obtain the values of different frequency bands, and finally display them dynamically. I used the QMediaPlayer and QMeidaPlaylist classes to play music. I didn't use the Phonon framework because the multimedia framework is no longer used after Qt5.0.

7.4 Test implementation

Reprinted please indicate the source: dunni column http://blog.csdn.net/u012027907



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.