qt imitation QQ main panel interface
QT Imitation QQ main panel interface effect diagram end
Effect Chart
It is worth noting here, QQ level settings, has been listed to expand the search triangle when the rotation effect
QQMainWindow.cpp #include "qqmainwindow.h" #include "contactitem.h" #include "rootcontatitem.h" #include " Skinwindow.h "#include <QPainter> #include <QMouseEvent> #include <QSpacerItem> #include < Qproxystyle> #include <QTimer> class customproxystyle:public Qproxystyle {public:virtual void Drawprimit
Ive (primitiveelement element, const qstyleoption * option, qpainter * painter, const qwidget * widget = 0) const
{if (Pe_framefocusrect = = Element) {return;
else {qproxystyle::d rawprimitive (element, option, painter, widget);
}
}
};
Qqmainwindow::qqmainwindow (Qwidget *parent): Basicwindow (parent) {UI.SETUPUI (this);
M_stylename = "MainWindow";
Loadstylesheet ("MainWindow");
Initcontrol ();
qtimer* timer = new Qtimer (this);
Timer->setinterval (500);
Connect (timer, &qtimer::timeout, [this] () {static int level = 0; if (level =%) {level = 0;
} setlevelpixmap (level);
level++;
});
Timer->start (); } Qqmainwindow::~qqmainwindow () {} void Qqmainwindow::initcontrol () {Ui.treewidget->setstyle (new CustomProxySt
YLE);
Setlevelpixmap (0);
Setusername (Qstring::fromlocal8bit ("Rain Tiango-Work number");
Setheadpixmap (":/qqmainwindow/resources/mainwindow/yutiange.jpg");
Setstatusmenuicon (":/qqmainwindow/resources/mainwindow/statussucceeded.png");
Qhboxlayout *flowlayout = new Qhboxlayout ();
Flowlayout->setcontentsmargins (0, 0, 0, 0);
Flowlayout->setspacing (2);
Flowlayout->addwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/app_7.png", "app_7"));
Flowlayout->addwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/app_2.png", "app_2"));
Flowlayout->addwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/app_3.png", "App_3")); Flowlayout->aDdwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/app_4.png", "App_4"));
Flowlayout->addwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/app_5.png", "app_5"));
Flowlayout->addwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/app_6.png", "app_6"));
Flowlayout->addstretch ();
Flowlayout->addwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/skin.png", "App_skin"));
Ui.appwidget->setlayout (FlowLayout); Ui.bottomlayout_up->addwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/app_10.png", "
App_10 ")); Ui.bottomlayout_up->addwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/app_8.png", "app
_8 ")); Ui.bottomlayout_up->addwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/app_11.png", "
App_11 ")); Ui.bottomlayout_up->addwidget (Addotherappextension (":/qqmainwindow/resources/mainwindow/app/app_9.png", "APP_9 "));
Ui.bottomlayout_up->addstretch ();
Ui.lineedit->installeventfilter (this);
Ui.searchlineedit->installeventfilter (this);
Initcontacttree ();
Initstrangertree ();
Connect (ui.sysmin, SIGNAL (clicked (bool)), this, SLOT (Onshowmin (bool));
Connect (Ui.sysclose, SIGNAL (clicked (bool)), this, SLOT (Onshowclose (bool)); } void Qqmainwindow::setheadpixmap (const qstring& headpath) {Ui.headlabel->setpixmap getroundimage (QPixmap (H
Eadpath), Qpixmap (":/qqmainwindow/resources/mainwindow/head_mask.png"), Ui.headlabel->size ());
} void Qqmainwindow::setusername (const qstring& username) {ui.namelabel->adjustsize ();
QString name = Ui.namelabel->fontmetrics (). Elidedtext (username, qt::elideright, ui.namelabel->width ());
Ui.namelabel->settext (name); } void Qqmainwindow::setstatusmenuicon (const qstring& statuspath) {qpixmap Statusbtnpixmap (ui.statusBtn->size
());
Statusbtnpixmap.fill (qt::transparent); QpaInter painter (&statusbtnpixmap);
Painter.drawpixmap (4, 4, Qpixmap (Statuspath));
Painter.drawpixmap (3, Qpixmap (":/qqmainwindow/resources/mainwindow/arrow_normal.gft.png"));
Ui.statusbtn->seticon (STATUSBTNPIXMAP);
Ui.statusbtn->seticonsize (Ui.statusbtn->size ());
} void Qqmainwindow::setlevelpixmap (int level) {Qpixmap Levelpixmap (ui.levelbtn->size ());
Levelpixmap.fill (qt::transparent);
qpainter painter (&levelpixmap);
Painter.drawpixmap (0, 4, Qpixmap (":/qqmainwindow/resources/mainwindow/lv.png")); int unitnum = level/1% 10;//fetch single-digit int tennum = level/10% 10;//take 10 digits//10 bit Painter.drawpixmap (4, QPIXM
AP (":/qqmainwindow/resources/mainwindow/levelvalue.png"), Tennum * 6, 0, 6, 7);
Single-digit Painter.drawpixmap (4, Qpixmap (":/qqmainwindow/resources/mainwindow/levelvalue.png"), Unitnum * 6, 0, 6, 7);
Ui.levelbtn->seticon (LEVELPIXMAP);
Ui.levelbtn->seticonsize (Ui.levelbtn->size ()); } qwidget* QQmainwindow::addotherappextension (const qstring& AppPath, const qstring& appName) {qpushbutton* btn = new QPu
Shbutton (this);
Btn->setfixedsize (20, 20);
Qpixmap Pixmap (Btn->size ());
Pixmap.fill (qt::transparent);
qpainter painter (&pixmap);
Qpixmap Apppixmap (AppPath);
Painter.drawpixmap ((Btn->width ()-apppixmap.width ())/2, (Btn->height ()-apppixmap.height ())/2, AppPixmap);
Btn->seticon (PIXMAP);
Btn->seticonsize (Btn->size ());
Btn->setproperty ("Hasborder", true);
Btn->setobjectname (AppName);
Connect (BTN, &qpushbutton::clicked, this, &qqmainwindow::onappiconcliked);
return BTN; } void Qqmainwindow::onappiconcliked () {if (Sender ()->objectname () = = "App_skin") {skinwindow* skinw
Indow = new Skinwindow ();
Skinwindow->show ();
} void Qqmainwindow::resizeevent (Qresizeevent *event) {setusername (Qstring::fromlocal8bit ("Rain 田哥-Work number"); __super::resizeevenT (event); BOOL Qqmainwindow::eventfilter (QObject *obj, qevent *event) {if (Ui.searchlineedit = obj) {if (event ->type () = = Qevent::focusin) {ui.searchwidget->setstylesheet ("Qwidget#searchwidget {background- Color:rgb (255, 255, 255);} \ qpushbutton#searchbtn {border-image:url (:/qqmainwindow/resources/mainwindow/ Search/main_search_deldown.png);} \ qpushbutton#searchbtn:hover {border-image:url (:/qqmainwindow/resources/mainw Indow/search/main_search_delhighlight.png);} \ qpushbutton#searchbtn:pressed{Border-image:url (:/qqmainwindow/resources/mai
nwindow/search/main_search_delhighdown.png);} "); else if (event->type () = = Qevent::focusout) {Ui.searchwidget->setstylesheet (QString ("Qwidget#se Archwidget {Background-color:rgba (%1,%2,%3,50);}
\ qpushbutton#searchbtn {Border-image:url (:/qqmainwindow/resources/mainwindow/search/search_icon.png);} ").
Arg (m_colorbackground.red ()). Arg (M_colorbackground.green ()). Arg (M_colorbackground.blue ()));
} return __super::eventfilter (obj, event); } void Qqmainwindow::mousepressevent (Qmouseevent *event) {if Qapp->widgetat (Event->pos ())!= Ui.lineEdit
;& Ui.lineedit->hasfocus ()) {ui.lineedit->clearfocus ();
else if (Qapp->widgetat (Event->pos ())!= ui.searchlineedit && Ui.searchlineedit->hasfocus ()) {
Ui.searchlineedit->clearfocus ();
} __super::mousepressevent (event); } void Qqmainwindow::initcontacttree () {//expand and shrink signal to achieve change of my triangular picture; Connect (Ui.treewidget, SIGNAL (itemclicked Qtreewi
Dgetitem *, int)), this, SLOT (onitemclicked (Qtreewidgetitem *, int)));
Connect (Ui.treewidget, SIGNAL (itemexpanded (Qtreewidgetitem *)), this, SLOT (onitemexpanded (Qtreewidgetitem *))); COnnect (Ui.treewidget, SIGNAL (itemcollapsed (Qtreewidgetitem *)), this, SLOT (onitemcollapsed (Qtreewidgetitem *)));
Group node Qtreewidgetitem *prootfrienditem = new Qtreewidgetitem ();
Prootfrienditem->setchildindicatorpolicy (Qtreewidgetitem::showindicator);
Set data to distinguish whether the item is a grouping node or a child node, 0 represents a grouping node, and 1 represents a child node Prootfrienditem->setdata (0, qt::userrole, 0);
Rootcontatitem *pitemname = new Rootcontatitem (ui.treewidget);
int nmyfriendnum = 6;
QString qsgroupname = Qstring::fromlocal8bit ("My friend%1/%2"). Arg (0). Arg (Nmyfriendnum);
Pitemname->settext (Qsgroupname);
Rub into the packet node Ui.treewidget->addtoplevelitem (prootfrienditem);
Ui.treewidget->setitemwidget (prootfrienditem, 0, Pitemname);
for (int nindex = 0; nindex < nmyfriendnum; ++nindex) {//Add child node Addmyfriendinfo (Prootfrienditem); } void Qqmainwindow::addmyfriendinfo (qtreewidgetitem* prootgroupitem) {Qtreewidgetitem *pchild = new QTreeWidge
TItem ();
Add child nodes Pchild->setdata (0, Qt::userrole, 1);
contactitem* Pcontactitem = new ContactItem (ui.treewidget); Pcontactitem->setheadpixmap (Getroundimage qpixmap (":/qqmainwindow/resources/mainwindow/yutiange.jpg"),
Qpixmap (":/qqmainwindow/resources/mainwindow/head_mask.png"), Pcontactitem->getheadlabelsize ());
Pcontactitem->setusername (Qstring::fromlocal8bit ("Rain Tiango-Work number");
Pcontactitem->setsignname (Qstring::fromlocal8bit ("Welcome to the Rain field work number"));
Prootgroupitem->addchild (pchild);
Ui.treewidget->setitemwidget (pchild, 0, Pcontactitem);
} void Qqmainwindow::initstrangertree () {//group node Qtreewidgetitem *prootfrienditem = new Qtreewidgetitem ();
Prootfrienditem->setchildindicatorpolicy (Qtreewidgetitem::showindicator);
Set data to distinguish whether the item is a grouping node or a child node, 0 represents a grouping node, and 1 represents a child node Prootfrienditem->setdata (0, qt::userrole, 0);
Rootcontatitem *pitemname = new Rootcontatitem (ui.treewidget);
int nmyfriendnum = 8; QString qsgroupname = Qstring::fromlocal8bit ("Stranger%1/%2"). Arg (0). Arg (Nmyfriendnum);
Pitemname->settext (Qsgroupname);
Rub into the packet node Ui.treewidget->addtoplevelitem (prootfrienditem);
Ui.treewidget->setitemwidget (prootfrienditem, 0, Pitemname);
for (int nindex = 0; nindex < nmyfriendnum; ++nindex) {//Add child node Addstarngerinfo (Prootfrienditem); } void Qqmainwindow::addstarngerinfo (qtreewidgetitem* prootgroupitem) {Qtreewidgetitem *pchild = new QTreeWidge
TItem ();
Add sub Nodes pchild->setdata (0, Qt::userrole, 1);
contactitem* Pcontactitem = new ContactItem (ui.treewidget); Pcontactitem->setheadpixmap (Getroundimage qpixmap (":/qqmainwindow/resources/mainwindow/yutiange.jpg"),
Qpixmap (":/qqmainwindow/resources/mainwindow/head_mask.png"), Pcontactitem->getheadlabelsize ());
Pcontactitem->setusername (Qstring::fromlocal8bit ("Rain Tiango-Work number-stranger"));
Pcontactitem->setsignname (Qstring::fromlocal8bit ("Welcome to the work of the rain Field-Stranger"));
Prootgroupitem->addchild (pchild); UI.treewidget->setitemwidget (pchild, 0, Pcontactitem); } void qqmainwindow::onitemclicked (Qtreewidgetitem * Item, int column) {bool Bischild = item->data (0, Qt::userrol
e). Tobool ();
if (!bischild) {item->setexpanded (!item->isexpanded ()); } void qqmainwindow::onitemexpanded (Qtreewidgetitem * Item) {bool Bischild = item->data (0, qt::userrole). ToBool
(); if (!bischild) {Rootcontatitem *prootitem = dynamic_cast<rootcontatitem*> (Ui.treewidget->itemwidget (
Item, 0));
if (Prootitem) {prootitem->setexpanded (true); }} void Qqmainwindow::onitemcollapsed (Qtreewidgetitem * Item) {bool Bischild = item->data (0, Qt::userrole)
. Tobool (); if (!bischild) {Rootcontatitem *prootitem = dynamic_cast<rootcontatitem*> (Ui.treewidget->itemwidget (
Item, 0));
if (Prootitem) {prootitem->setexpanded (false); }
}
}
SkinWindow.cpp #include "skinwindow.h" #include "qclicklabel.h" #include "Notifymanager.h" Skinwindow::skinwindow (
Qwidget *parent): Basicwindow (parent) {UI.SETUPUI (this);
M_stylename = "Skinwindow";
Initcontrol ();
SetAttribute (Qt::wa_deleteonclose);
Loadstylesheet ("Skinwindow"); } Skinwindow::~skinwindow () {} void Skinwindow::initcontrol () {qlist<qcolor> colorlst = {Qcolor (22, 154, 2 (Qcolor, 138, 221), Qcolor (166, Qcolor,), 218, Qcolor (177, 99, 159), Qcolor (Qcolor, Bayi, MB), Qcolor (160, 156, 199), Qcolor (169, 172), Qco
Lor (183, 154), Qcolor (128, +,), Qcolor (240, 188, 189)}; for (int row = 0; row < 3, row++) {for (int column = 0; column < 4; column++) {QCl
icklabel* label = new Qclicklabel (this);
Label->setcursor (Qt::P ointinghandcursor); Connect (label, &qclicKlabel::clicked, [Row, column, Colorlst, this] () {notifymanager::getinstance ()->notifyotherwindowchange
Skin (colorlst.at (4 * row + column));
});
Label->setfixedsize (84, 84);
Qpalette Palette;
Palette.setcolor (Qpalette::background, colorlst.at (4 * row + column));
Label->setautofillbackground (TRUE);
Label->setpalette (palette);
Ui.gridlayout->addwidget (label, Row, column);
} Connect (Ui.sysmin, SIGNAL (clicked (bool)), this, SLOT (Onshowmin (bool));
Connect (Ui.sysclose, SIGNAL (clicked (bool)), this, SLOT (Onshowclose (bool)); }
Parent node Item #include "rootcontatitem.h" #include <QPainter> #include <QPropertyAnimation> #include < Qdebug> Rootcontatitem::rootcontatitem (Qwidget *parent): Qlabel (parent), m_rotation (0) {setfixedheight (
32);
Setsizepolicy (qsizepolicy::expanding, qsizepolicy::fixed);
M_animation = new Qpropertyanimation (this, "rotation");
M_animation->setduration (50);
M_animation->seteasingcurve (Qeasingcurve::inquad); } rootcontatitem::~rootcontatitem () {} void rootcontatitem::setexpanded (bool expand) {if (expand) {m
_animation->setendvalue (90);
else {m_animation->setendvalue (0);
} m_animation->start ();
int rootcontatitem::rotation () {return m_rotation;}
void rootcontatitem::setrotation (int rotation) {m_rotation = rotation;
Update ();
} void Rootcontatitem::settext (const qstring& title) {M_titletext = title;
Update (); } void Rootcontatitem::p aintevent (qpaintEvent *event) {qpainter painter (this);
{Painter.setrenderhint (qpainter::textantialiasing, true);
Qfont font;
Font.setpointsize (10);
Painter.setfont (font); Painter.drawtext (0, Width ()-, height (), Qt::alignleft |
Qt::alignvcenter, M_titletext);
{Painter.setrenderhint (Qpainter::smoothpixmaptransform, true);
Painter.save ();
Background Figure Qpixmap Pixmap (":/qqmainwindow/resources/mainwindow/arrow.png");
Qpixmap Tmppixmap (Pixmap.size ());
Tmppixmap.fill (qt::transparent);
Qpainter p (&tmppixmap);
P.setrenderhint (Qpainter::smoothpixmaptransform, true);
Rotate m_rotation Angle P.translate (Pixmap.width ()/2, Pixmap.height ()/2);
P.rotate (m_rotation);
P.drawpixmap (0-pixmap.width ()/2, 0-pixmap.height ()/2, pixmap);
Painter.drawpixmap (6, (height ()-pixmap.height ())/2, Tmppixmap);
Painter.restore (); } __super::p aintevent (event);
}
End
Just for the record, just for sharing! Willing to write can be helpful to you. Don't forget to order a praise, thank you ~
————— – Need engineering documents, can add my QQ ————— –
QQ level setting effect, and Buddy list expansion and contraction when the triangular symbol rotation animation effect. Everyone can be worth noting.