Implement the WebKugou client using QT

Source: Internet
Author: User

Today I read a little QWebView, so I came up with the idea of making web.kugou.com a client. After one day, this is the final result:


650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/124323AZ-0.jpg "title =" webkugou1.jpg "alt =" 192957474.jpg"/>


650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/1243231F6-1.jpg "title =" QQ20131013193322.jpg "alt =" 193400888.jpg"/>


Because the blue interface is loaded by default, the interface is adapted to the default blue.


The Qt version is 5.1.1. The following code is used:

WebKugouWidget.pro

#-------------------------------------------------#WebKugouWidget.pro#-------------------------------------------------## Project created by QtCreator 2013-10-13T11:45:54##-------------------------------------------------QT       += core gui webkitwidgetsgreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = WebKugouWidgetTEMPLATE = appSOURCES += main.cpp \    webkugouwidget.cppHEADERS  += \    webkugouwidget.h


Webkugouwidget. h

// Webkugouwidget. h # ifndef WIDGET_H # define WIDGET_H # include <strong> class WebKugouWidget: public QWidget {Q_OBJECTpublic: WebKugouWidget (QWidget * parent = 0 );~ WebKugouWidget (); private: QWebView * kgwebView; QLabel * tittleBar; QToolButton * closeButton; interval * minToTrayBtn; QPushButton * minButton; private: // rewrite the mouse event to move the window bool isPress; QPoint dragPosition; void mousePressEvent (QMouseEvent *); void mouseMoveEvent (QMouseEvent *); void mouseReleaseEvent (QMouseEvent *); private slots: void container (); // disable void closeEx (); signals: // to facilitate the embedding of this Code into other projects, do not minimize to the tray // click to minimize to the tray, send the following signal void minimizedTOTray ();}; # endif // WIDGET_H


Webkugouwidget. cpp

// Webkugouwidget. cpp ---------------------------- # include "webkugouwidget. h "WebKugouWidget: WebKugouWidget (QWidget * parent): QWidget (parent), isPress (false) {// set the plug-in path, fash plug-in -------------------- // copy NPSWF32_11_8_800_168.dll to the QApplication: addLibraryPath (". /plugins "); QWebSettings * settings = QWebSettings: globalSettings (); settings-> setAttribute (QWebSettings: PluginsEnabled, true); // allow plug-in settings-> setAttribute (QWebSettings:: JavascriptEnabled, true); // JavaScript settings-> setAttribute (QWebSettings: javasextrasenabled, true); // settings-> setAttribute (QWebSettings: JavascriptCanOpenWindows, true ); // remove the system border setWindowFlags (Qt: FramelessWindowHint); kgwebView = new QWebView (this); kgwebView-> page ()-> setLinkDelegationPolicy (QWebPage: DelegateAllLinks ); // close the Horizontal scroll bar kgwebView-> page ()-> mainFrame ()-> setScrollBarPolicy (Qt: Horizontal, Qt: ScrollBarAlwaysOff); kgwebView-> load (QUrl (" http://web.kugou.com/index.html ? "); // The following settings are better: kgwebView-> setGeometry (-740,508, 1,160,234); // The default Interface rgb is rgb) kgwebView-> setStyleSheet ("rgba (1,160,234, 0);"); // used to display WebKugou, drag the window, and shield controls on the top of the web cool dog; tittleBar = new QLabel (this ); tittleBar-> setGeometry (740,510,); tittleBar-> setText ("WebKugou"); tittleBar-> setCursor (Qt: SizeAllCursor); this-> resize ); // close the button closeButton = new QToolButton (this); connect (closeButton, SIGNAL (clicke D (), this, SLOT (closeEx (); closeButton-> setGeometry (740-,); closeButton-> setText ("× "); closeButton-> setToolTip (tr ("off"); // minimized to the tray minToTrayBtn = new QPushButton ("", this); minToTrayBtn-> setGeometry (740-25-, 0, 25, 25); minToTrayBtn-> setToolTip (tr ("minimized to tray"); connect (minToTrayBtn, SIGNAL (clicked (), this, SLOT (emitminimizedTOTray ())); // minimize minButton = new QPushButton ("-", this); connect (minButton, SIGNAL (clicked (), this, SLOT (showMinimized (); minButton-> setGeometry (740-25-25-25, 0, 25, 25 ); minButton-> setToolTip (tr ("minimal"); // set the style table this-> setStyleSheet (QString ("WebKugouWidget {border: 5px solid gray; border-color: rgb (1,160,234); font-size: 12pt; rgb (1,160,234); color: white} "" QToolButton {font: 13pt \ "Arial \"; color: white; rgba (0, 0, 0);} "" QToolButton: hover {border: 0px solid; color: black; background-colo R: qlineargradient (spread: pad, x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba (254, 67,101,220), stop: 1 rgba (254, 67,101, 0);} "" QPushButton {color: white; rgba (,);} "" QPushButton: hover {border: 0px solid; color: black; background-color: qlineargradient (spread: pad, x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba (170,138, 87,220 ), stop: 1 rgba (170,138, 87, 0);} "" QLabel {color: white; font-size: 15pt; background: qlinearg Radient (x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb (3,208,234), stop: 0.8 rgb (1,160,234), stop: 1 rgb (1,160,234);} ");} WebKugouWidget ::~ WebKugouWidget () {} void WebKugouWidget: closeEx () {this-> hide (); exit (0);} void WebKugouWidget: emitminimizedTOTray () {emit minimizedTOTray ();} void WebKugouWidget: mousePressEvent (QMouseEvent * event) {if (event-> button () = Qt: LeftButton) {dragPosition = event-> globalPos () -this-> pos (); isPress = true; event-> accept () ;}} void WebKugouWidget: mouseMoveEvent (QMouseEvent * event) {if (isPress & event-> buttons () & Qt: LeftButton) {move (event-> globalPos ()-dragPosition ); event-> accept () ;}} void WebKugouWidget: mouseReleaseEvent (QMouseEvent * event) {if (event-> button () = Qt: LeftButton) {isPress = false; event-> accept ();}}


Main. cpp

//main.cpp-----------------------#include "webkugouwidget.h"#include <QApplication>int main(int argc, char *argv[]){    QApplication a(argc, argv);    WebKugouWidget w;    w.show();    return a.exec();}


Use the QLabeltittleBar) control to block the top-side Image Location of webkugou. Shield the system framework, overwrite the mouse event, and drag the window. At the same time, the background gradient makes it a natural transition to the playing interface.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/12432351E-2.jpg "title =" QQ20131013195842.jpg "alt =" 200015576.jpg"/>


The webkitwidgets of Qt is used to conveniently load webpage content. During debuggingNPSWF32_11_8_800_168.dll or other versionsNPSWF32. Dll) copy to the pugins directory of Release. Otherwise, flash cannot be loaded. You need to use Release for debugging. For some reason, debugging will crash when loading flash.

This article from the "water cainiao" blog, please be sure to keep this source http://cpp51.blog.51cto.com/5346598/1308457

Related Article

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.