分享

Qt浅谈之三十五仿QQ设置面板功能

 QomoIT 2016-08-03

一、简介

        模仿QQ系统设置的面板:上面的导航切换选项卡使用QTabWidget,左侧导航使用QListWidget,右侧的显示区域使用QScrollArea控件;主要使用垂直滚动条的valueChanged事件和QListWidget的itemClicked事件;通过调用QWidget的visibleRegion().isEmpty() 判断QScrollArea中滑动过的区域,通过垂直滚动条的setSliderPosition方法设置QScrollArea的新的区域。


二、详解

1、模仿QQ系统设置的面板

(1)代码

  • settingpanel.h:
  1. #ifndef SETTINGPANEL_H  
  2. #define SETTINGPANEL_H  
  3.   
  4. #include <QtGui>  
  5. #include "epushbutton.h"  
  6.   
  7. class SettingPanel : public QWidget  
  8. {  
  9.     Q_OBJECT  
  10.   
  11. public:  
  12.     SettingPanel(QWidget *parent = 0);  
  13.     ~SettingPanel();  
  14.   
  15. protected:  
  16.      void paintEvent(QPaintEvent *event);  
  17.      void mousePressEvent(QMouseEvent *event);  
  18.      void mouseReleaseEvent(QMouseEvent *event);  
  19.      void mouseMoveEvent(QMouseEvent *event);  
  20.      void resizeEvent(QResizeEvent *event);  
  21.   
  22. private:  
  23.      void initTabOneWidget();  
  24.      void initTabTwoWidget();  
  25.      void initTabThreeWidget();  
  26.   
  27. private slots:  
  28.      void slotCurrentChanged(int index);  
  29.      void slotItemClicked(QListWidgetItem *item);  
  30.      void slotValueChanged(int value);  
  31.   
  32. private:  
  33.     QPoint movePoint;  
  34.     bool mousePress;  
  35.     EPushButton *minButton;  
  36.     EPushButton *closeButton;  
  37.     QRect rectMove;  
  38.     QTabWidget *tabWidget;  
  39.     QListWidget *contentsWidget;  
  40.     QWidget *widgetScrollArea;  
  41.     QScrollArea *scrollArea;  
  42.     QWidget *loginWidget;  
  43.     QWidget *panelWidget;  
  44.     QWidget *statusWidget;  
  45.     QWidget *sessionWidget;  
  46.   
  47.     QWidget *passwordWidget;  
  48.     QWidget *qqlockWidget;  
  49.   
  50.     QWidget *spaceWidget;  
  51.     bool signFlag;  
  52. };  
  53.   
  54. #endif // SETTINGPANEL_H  

  • settingpanel.cpp:

  1. #include "settingpanel.h"  
  2.   
  3. SettingPanel::SettingPanel(QWidget *parent)  
  4.     : QWidget(parent, Qt::FramelessWindowHint)  
  5.     , mousePress(false)  
  6.     , signFlag(false)  
  7.     , loginWidget(NULL)  
  8.     , panelWidget(NULL)  
  9.     , statusWidget(NULL)  
  10.     , sessionWidget(NULL)  
  11.     , passwordWidget(NULL)  
  12.     , qqlockWidget(NULL)  
  13.     , spaceWidget(NULL)  
  14. {  
  15.     resize(700, 500);  
  16.     setStyleSheet("QCheckBox{font-family:arial;font-size:13px;border-radius:2px;color:#000000;}"  
  17.                   "QCheckBox::indicator:checked{color:#FF0000}"  
  18.                   "QTabWidget::pane{border:none;}"  
  19.                   "QTabWidget::tab-bar{alignment:left;}"  
  20.                   "QTabBar::tab{background:transparent;color:#000000;min-width:100px;min-height:35px;}"  
  21.                   "QTabBar::tab:hover{background:rgb(255, 255, 255, 255);}"  
  22.                   "QTabBar::tab:selected{border-color: white;color:green;padding-left:5px}"  
  23.                   "QListWidget{background:rgba(240,240,240,255);color:#000000;border:0px solid gray;padding:0px;}"  
  24.                   "QListWidget::item{width:94px;height:38px;border:0px solid gray;padding-left:24px;}"  
  25.                   "QListWidget::item:selected:active{background:#FFFFFF;color:#19649F;border-width:-1;}"  
  26.                   "QListWidget::item:selected{background:#FFFFFF;color:#19649F;}"  
  27.                   "QLabel,QRadioButton{background:transparent;color:#000000;font-family:arial;font-size:13px;}"  
  28.   
  29.                   "QComboBox{border:1px solid #d7d7d7; border-radius: 3px; padding: 1px 3px 1px 3px;}"  
  30.                   "QComboBox:editable{background:transparent;}"  
  31.                   "QComboBox:!editable{background: #fbfbfb;color:#666666}"  
  32.                   "QComboBox::down-arrow:on {top: 1px;left: 1px;}"  
  33.                   "QComboBox QAbstractItemView::item{max-width:30px;min-height:20px;}"  
  34.                   );  
  35.     rectMove = QRect(0, 0, width(), 35);  
  36.   
  37.     tabWidget = new QTabWidget(this);  
  38.     tabWidget->setFocusPolicy(Qt::NoFocus);  
  39.     QWidget *tab1 = new QWidget(this);  
  40.     tab1->setStyleSheet("background:#FFFFFF");  
  41.     QWidget *tab2 = new QWidget(this);  
  42.     tab2->setStyleSheet("background:#FFFFFF");  
  43.     QWidget *tab3 = new QWidget(this);  
  44.     tab3->setStyleSheet("background:#FFFFFF");  
  45.     tabWidget->addTab(tab1, QIcon(":/setting.png"),tr("base setting"));  
  46.     tabWidget->addTab(tab2, QIcon(":/home.png"), tr("secure setting"));  
  47.     tabWidget->addTab(tab3, QIcon(":/status.png"), tr("power setting"));  
  48.     tabWidget->setCurrentIndex(0);  
  49.   
  50.     contentsWidget = new QListWidget(this);  
  51.     contentsWidget->setFocusPolicy(Qt::NoFocus);  
  52.     connect(contentsWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slotItemClicked(QListWidgetItem*)));  
  53.   
  54.     scrollArea = new QScrollArea(this);  
  55.     scrollArea->setStyleSheet("QScrollArea{background:transparent;}"  
  56.                               "QScrollBar::vertical{background:#35A739;border:-5px solid grey;margin:-2px 0px 0px 0px;width:8px;}"  
  57.                               "QScrollBar::horizontal{background:#35A739;border:0px solid #126691;height:10px;}"  
  58.                               "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {background:#D3D3D3;}"  
  59.                               );  
  60.   
  61.     scrollArea->setFrameShape(QFrame::NoFrame);  
  62.     scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);  
  63.     scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);  
  64.     scrollArea->setFocusPolicy(Qt::NoFocus);  
  65.     connect(scrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int)));  
  66.   
  67.     connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int)));  
  68.     slotCurrentChanged(0);  
  69.   
  70.     minButton = new EPushButton(this);  
  71.     minButton->setPixName(":/min");  
  72.     minButton->setToolTip(tr("minimize"));  
  73.     connect(minButton, SIGNAL(clicked()), this, SLOT(showMinimized()));  
  74.   
  75.     closeButton = new EPushButton(this);  
  76.     closeButton->setPixName(":/close");  
  77.     closeButton->setToolTip(tr("close"));  
  78.     connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));  
  79. }  
  80.   
  81. SettingPanel::~SettingPanel()  
  82. {  
  83.   
  84. }  
  85.   
  86. void SettingPanel::resizeEvent(QResizeEvent *event)  
  87. {  
  88.     tabWidget->setGeometry(0, 35, this->width(), this->height() - 35);  
  89.     contentsWidget->setGeometry(0, 71, 130, this->height() - 71);  
  90.     scrollArea->setGeometry(131, 72, this->width() - 132, this->height() - 73);  
  91.     minButton->move(width() - 27 - closeButton->width(), 6);  
  92.     closeButton->move(width() - 27, 6);  
  93.     move((QApplication::desktop()->width() - width())/2,  (QApplication::desktop()->height() - height())/2);  
  94.     QWidget::resizeEvent(event);  
  95. }  
  96.   
  97. void SettingPanel::initTabOneWidget()  
  98. {  
  99.     /************loginWidget**************/  
  100.     loginWidget = new QWidget(widgetScrollArea);  
  101.     loginWidget->show();  
  102.     QLabel *label = new QLabel(loginWidget);  
  103.     label->setText(tr("login:"));  
  104.     label->setGeometry(30, 10, 50, 30);  
  105.     label->show();  
  106.     QCheckBox *first = new QCheckBox(loginWidget);  
  107.     first->setFocusPolicy(Qt::NoFocus);  
  108.     first->setText(tr("start QQ when starting"));  
  109.     first->setGeometry(100, 10, 300, 30);  
  110.     first->show();  
  111.     QCheckBox *second = new QCheckBox(loginWidget);  
  112.     second->setFocusPolicy(Qt::NoFocus);  
  113.     second->setText(tr("login when starting QQ"));  
  114.     second->setGeometry(100, 40, 300, 30);  
  115.     second->show();  
  116.     QCheckBox *third = new QCheckBox(loginWidget);  
  117.     third->setFocusPolicy(Qt::NoFocus);  
  118.     third->setChecked(true);  
  119.     third->setText(tr("open the tips always"));  
  120.     third->setGeometry(100, 70, 300, 30);  
  121.     third->show();  
  122.     QCheckBox *forth = new QCheckBox(loginWidget);  
  123.     forth->setFocusPolicy(Qt::NoFocus);  
  124.     forth->setText(tr("open the previous session when logining"));  
  125.     forth->setGeometry(100, 100, 300, 30);  
  126.     forth->show();  
  127.     QCheckBox *five = new QCheckBox(loginWidget);  
  128.     five->setFocusPolicy(Qt::NoFocus);  
  129.     five->setText(tr("open the tips always"));  
  130.     five->setGeometry(100, 130, 300, 30);  
  131.     five->show();  
  132.     QCheckBox *sixth = new QCheckBox(loginWidget);  
  133.     sixth->setFocusPolicy(Qt::NoFocus);  
  134.     sixth->setChecked(true);  
  135.     sixth->setText(tr("start phone qq when leaving"));  
  136.     sixth->setGeometry(100, 160, 300, 30);  
  137.     sixth->show();  
  138.     QCheckBox *seventh = new QCheckBox(loginWidget);  
  139.     seventh->setFocusPolicy(Qt::NoFocus);  
  140.     seventh->setChecked(true);  
  141.     seventh->setText(tr("diskplay the waiting tips when logining"));  
  142.     seventh->setGeometry(100, 190, 300, 30);  
  143.     seventh->show();  
  144.     loginWidget->setGeometry(0, 0, 555, 220);  
  145.     /************panelWidget**************/  
  146.     panelWidget = new QWidget(widgetScrollArea);  
  147.     panelWidget->show();  
  148.     QLabel *plabel = new QLabel(panelWidget);  
  149.     plabel->setText(tr("mainpanel:"));  
  150.     plabel->setGeometry(30, 10, 50, 30);  
  151.     plabel->show();  
  152.     QCheckBox *pfirst = new QCheckBox(panelWidget);  
  153.     pfirst->setChecked(true);  
  154.     pfirst->setFocusPolicy(Qt::NoFocus);  
  155.     pfirst->setText(tr("stays on top always"));  
  156.     pfirst->setGeometry(100, 10, 300, 30);  
  157.     pfirst->show();  
  158.     QCheckBox *psecond = new QCheckBox(panelWidget);  
  159.     psecond->setChecked(true);  
  160.     psecond->setFocusPolicy(Qt::NoFocus);  
  161.     psecond->setText(tr("hide when  skiming the edge of desktop"));  
  162.     psecond->setGeometry(100, 40, 300, 30);  
  163.     psecond->show();  
  164.     QCheckBox *pthird = new QCheckBox(panelWidget);  
  165.     pthird->setFocusPolicy(Qt::NoFocus);  
  166.     pthird->setChecked(true);  
  167.     pthird->setText(tr("display the icon of qq at the taskbar"));  
  168.     pthird->setGeometry(100, 70, 300, 30);  
  169.     pthird->show();  
  170.     QLabel *pforth = new QLabel(panelWidget);  
  171.     pforth->setText(tr("when closing the mainpanel:"));  
  172.     pforth->setGeometry(100, 100, 300, 30);  
  173.     pforth->show();  
  174.     QRadioButton *hideRadio = new QRadioButton(panelWidget);  
  175.     hideRadio->setFocusPolicy(Qt::NoFocus);  
  176.     hideRadio->setText(tr("hide at the taskbar and do not exit"));  
  177.     hideRadio->setGeometry(120, 130, 300, 30);  
  178.     hideRadio->show();  
  179.     QRadioButton *exitRadio = new QRadioButton(panelWidget);  
  180.     exitRadio->setFocusPolicy(Qt::NoFocus);  
  181.     exitRadio->setChecked(true);  
  182.     exitRadio->setText(tr("exit the program"));  
  183.     exitRadio->setGeometry(120, 160, 300, 30);  
  184.     exitRadio->show();  
  185.     panelWidget->setGeometry(0, 220, 555, 190);  
  186.     /************statusWidget**************/  
  187.     statusWidget = new QWidget(widgetScrollArea);  
  188.     statusWidget->show();  
  189.     QLabel *slabel = new QLabel(statusWidget);  
  190.     slabel->setText(tr("status:"));  
  191.     slabel->setGeometry(30, 10, 50, 30);  
  192.     slabel->show();  
  193.     QLabel *slabelsecond = new QLabel(statusWidget);  
  194.     slabelsecond->setText(tr("the status of logining:"));  
  195.     slabelsecond->setGeometry(100, 10, 150, 30);  
  196.     slabelsecond->show();  
  197.     QComboBox *combox = new QComboBox(statusWidget);  
  198.     combox->setFocusPolicy(Qt::NoFocus);  
  199.     combox->setStyle(new QPlastiqueStyle);  
  200.     combox->addItems(QStringList() << tr("hide") << tr("oneline") << tr("busy") << tr("leave"));  
  201.     combox->setGeometry(200, 12, 80, 24);  
  202.     combox->show();  
  203.     QCheckBox *ssecond = new QCheckBox(statusWidget);  
  204.     ssecond->setChecked(true);  
  205.     ssecond->setFocusPolicy(Qt::NoFocus);  
  206.     ssecond->setText(tr("switch to busy when running the program of fullscreen"));  
  207.     ssecond->setGeometry(100, 40, 300, 30);  
  208.     ssecond->show();  
  209.     QCheckBox *sthird = new QCheckBox(statusWidget);  
  210.     sthird->setFocusPolicy(Qt::NoFocus);  
  211.     sthird->setChecked(true);  
  212.     sthird->setText(tr("auto replay when leaving or busy"));  
  213.     sthird->setGeometry(100, 70, 300, 30);  
  214.     sthird->show();  
  215.     QCheckBox *sforth = new QCheckBox(statusWidget);  
  216.     sforth->setFocusPolicy(Qt::NoFocus);  
  217.     sforth->setText(tr("lock the qq when do not moving"));  
  218.     sforth->setGeometry(100, 100, 300, 30);  
  219.     sforth->show();  
  220.     statusWidget->setGeometry(0, 410, 555, 130);  
  221.     /************sessionWidget**************/  
  222.     sessionWidget = new QWidget(widgetScrollArea);  
  223.     sessionWidget->show();  
  224.     QLabel *elabel = new QLabel(sessionWidget);  
  225.     elabel->setText(tr("session:"));  
  226.     elabel->setGeometry(30, 10, 50, 30);  
  227.     elabel->show();  
  228.     QCheckBox *efirst = new QCheckBox(sessionWidget);  
  229.     efirst->setChecked(true);  
  230.     efirst->setFocusPolicy(Qt::NoFocus);  
  231.     efirst->setText(tr("use colourful bubble to chat"));  
  232.     efirst->setGeometry(100, 10, 300, 30);  
  233.     efirst->show();  
  234.     QCheckBox *esecond = new QCheckBox(sessionWidget);  
  235.     esecond->setChecked(true);  
  236.     esecond->setFocusPolicy(Qt::NoFocus);  
  237.     esecond->setText(tr("do not dispaly ad"));  
  238.     esecond->setGeometry(100, 40, 300, 30);  
  239.     esecond->show();  
  240.     QCheckBox *ethird = new QCheckBox(sessionWidget);  
  241.     ethird->setFocusPolicy(Qt::NoFocus);  
  242.     ethird->setText(tr("auto pop the panel when having massage"));  
  243.     ethird->setGeometry(100, 70, 300, 30);  
  244.     ethird->show();  
  245.     QCheckBox *eforth = new QCheckBox(sessionWidget);  
  246.     eforth->setChecked(true);  
  247.     eforth->setFocusPolicy(Qt::NoFocus);  
  248.     eforth->setText(tr("use autorun magic and supper expression"));  
  249.     eforth->setGeometry(100, 100, 300, 30);  
  250.     eforth->show();  
  251.     QCheckBox *efive = new QCheckBox(sessionWidget);  
  252.     efive->setChecked(true);  
  253.     efive->setFocusPolicy(Qt::NoFocus);  
  254.     efive->setText(tr("use moving feeling to char"));  
  255.     efive->setGeometry(100, 130, 300, 30);  
  256.     efive->show();  
  257.     QCheckBox *esixth = new QCheckBox(sessionWidget);  
  258.     esixth->setFocusPolicy(Qt::NoFocus);  
  259.     esixth->setChecked(true);  
  260.     esixth->setText(tr("display the window of char at the sidebar"));  
  261.     esixth->setGeometry(100, 160, 300, 30);  
  262.     esixth->show();  
  263.     QCheckBox *eseventh = new QCheckBox(sessionWidget);  
  264.     eseventh->setFocusPolicy(Qt::NoFocus);  
  265.     eseventh->setChecked(true);  
  266.     eseventh->setText(tr("allow the moving window"));  
  267.     eseventh->setGeometry(100, 190, 300, 30);  
  268.     eseventh->show();  
  269.     QCheckBox *eeighth = new QCheckBox(sessionWidget);  
  270.     eeighth->setFocusPolicy(Qt::NoFocus);  
  271.     eeighth->setChecked(true);  
  272.     eeighth->setText(tr("dispaly search tips"));  
  273.     eeighth->setGeometry(100, 210, 300, 30);  
  274.     eeighth->show();  
  275.     QCheckBox *enineth = new QCheckBox(sessionWidget);  
  276.     enineth->setFocusPolicy(Qt::NoFocus);  
  277.     enineth->setChecked(true);  
  278.     enineth->setText(tr("dispaly the history information"));  
  279.     enineth->setGeometry(100, 240, 300, 30);  
  280.     enineth->show();  
  281.     QCheckBox *etenth = new QCheckBox(sessionWidget);  
  282.     etenth->setFocusPolicy(Qt::NoFocus);  
  283.     etenth->setChecked(true);  
  284.     etenth->setText(tr("combine the session window"));  
  285.     etenth->setGeometry(100, 270, 300, 30);  
  286.     etenth->show();  
  287.     sessionWidget->setGeometry(0, 540, 555, 300 + 127);  
  288.   
  289.     widgetScrollArea->resize(555, 840+127);  
  290. }  
  291.   
  292. void SettingPanel::initTabTwoWidget()  
  293. {  
  294.     /************passwordWidget**************/  
  295.     passwordWidget = new QWidget(widgetScrollArea);  
  296.     passwordWidget->show();  
  297.     QLabel *label = new QLabel(passwordWidget);  
  298.     label->setText(tr("password:"));  
  299.     label->setGeometry(30, 10, 50, 30);  
  300.     label->show();  
  301.     QLabel *first = new QLabel(passwordWidget);  
  302.     first->setText(tr("do not remember the password:"));  
  303.     first->setGeometry(100, 10, 300, 30);  
  304.     first->show();  
  305.     QPushButton *second = new QPushButton(passwordWidget);  
  306.     second->setStyleSheet("QPushButton{border:1px solid lightgray;background:rgb(230,230,230);border-radius:3px;}"  
  307.                           "QPushButton:hover{border-color:green;background:#bee7fd;}");  
  308.     second->setFocusPolicy(Qt::NoFocus);  
  309.     second->setText(tr("cancel to remember password"));  
  310.     second->setGeometry(100, 40, 90, 25);  
  311.     second->show();  
  312.     QLabel *third = new QLabel(passwordWidget);  
  313.     third->setText(tr("make sure safe,please alter password regularly"));  
  314.     third->setGeometry(100, 70, 300, 30);  
  315.     third->show();  
  316.     QPushButton *forth = new QPushButton(passwordWidget);  
  317.     forth->setStyleSheet("QPushButton{border:1px solid lightgray;background:rgb(230,230,230);border-radius:3px;}"  
  318.                           "QPushButton:hover{border-color:green;color:#bee7fd;}");  
  319.     forth->setFocusPolicy(Qt::NoFocus);  
  320.     forth->setText(tr("alter password"));  
  321.     forth->setGeometry(100, 100, 60, 25);  
  322.     forth->show();  
  323.     QPushButton *forths = new QPushButton(passwordWidget);  
  324.     forths->setStyleSheet("QPushButton{border:1px solid lightgray;background:rgb(230,230,230);border-radius:3px;}"  
  325.                           "QPushButton:hover{border-color:green;color:#bee7fd;}");  
  326.     forths->setFocusPolicy(Qt::NoFocus);  
  327.     forths->setText(tr("apply for protecting password"));  
  328.     forths->setGeometry(170, 100, 90, 25);  
  329.     forths->show();  
  330.     QLabel *five = new QLabel(passwordWidget);  
  331.     five->setText(tr("some servers will use special password"));  
  332.     five->setGeometry(100, 130, 300, 30);  
  333.     five->show();  
  334.     QPushButton *sixth = new QPushButton(passwordWidget);  
  335.     sixth->setStyleSheet("QPushButton{border:1px solid lightgray;background:rgb(240,240,240);border-radius:3px;}"  
  336.                           "QPushButton:hover{border-color:green;color:#bee7fd;}");  
  337.     sixth->setFocusPolicy(Qt::NoFocus);  
  338.     sixth->setText(tr("manager special password"));  
  339.     sixth->setGeometry(100, 160, 90, 25);  
  340.     sixth->show();  
  341.     passwordWidget->setGeometry(0, 0, 555, 190);  
  342.     /************qqlockWidget**************/  
  343.     qqlockWidget = new QWidget(widgetScrollArea);  
  344.     qqlockWidget->show();  
  345.     QLabel *qlabel = new QLabel(qqlockWidget);  
  346.     qlabel->setText(tr("qqlock:"));  
  347.     qlabel->setGeometry(30, 10, 50, 30);  
  348.     qlabel->show();  
  349.     QRadioButton *firstRadio = new QRadioButton(qqlockWidget);  
  350.     firstRadio->setFocusPolicy(Qt::NoFocus);  
  351.     firstRadio->setChecked(true);  
  352.     firstRadio->setText(tr("qq password is used to unlock"));  
  353.     firstRadio->setGeometry(100, 10, 300, 30);  
  354.     firstRadio->show();  
  355.     QRadioButton *secondRadio = new QRadioButton(qqlockWidget);  
  356.     secondRadio->setFocusPolicy(Qt::NoFocus);  
  357.     secondRadio->setText(tr("special password is used to unlock"));  
  358.     secondRadio->setGeometry(100, 40, 300, 30);  
  359.     secondRadio->show();  
  360.     qqlockWidget->setGeometry(0, 190, 555, 70);  
  361.     widgetScrollArea->resize(555, 190+70+360);  
  362. }  
  363.   
  364. void SettingPanel::initTabThreeWidget()  
  365. {  
  366.     /************loginWidget**************/  
  367.     spaceWidget = new QWidget(widgetScrollArea);  
  368.     spaceWidget->show();  
  369.     QLabel *label = new QLabel(spaceWidget);  
  370.     label->setText(tr("spacepermission:"));  
  371.     label->setGeometry(30, 10, 60, 30);  
  372.     label->show();  
  373.     QCheckBox *first = new QCheckBox(spaceWidget);  
  374.     first->setFocusPolicy(Qt::NoFocus);  
  375.     first->setChecked(true);  
  376.     first->setText(tr("newly log and photos display on qq"));  
  377.     first->setGeometry(100, 10, 300, 30);  
  378.     first->show();  
  379.     QCheckBox *second = new QCheckBox(spaceWidget);  
  380.     second->setFocusPolicy(Qt::NoFocus);  
  381.     second->setText(tr("update sign when updating chat"));  
  382.     second->setGeometry(100, 40, 300, 30);  
  383.     second->show();  
  384.     QCheckBox *third = new QCheckBox(spaceWidget);  
  385.     third->setFocusPolicy(Qt::NoFocus);  
  386.     third->setChecked(true);  
  387.     third->setText(tr("notice you when you log is republished"));  
  388.     third->setGeometry(100, 70, 300, 30);  
  389.     third->show();  
  390.     QCheckBox *forth = new QCheckBox(spaceWidget);  
  391.     forth->setFocusPolicy(Qt::NoFocus);  
  392.     forth->setChecked(true);  
  393.     forth->setText(tr("notice you when you have new tips"));  
  394.     forth->setGeometry(100, 100, 300, 30);  
  395.     forth->show();  
  396.     QCheckBox *five = new QCheckBox(spaceWidget);  
  397.     five->setFocusPolicy(Qt::NoFocus);  
  398.     five->setChecked(true);  
  399.     five->setText(tr("display your newly application"));  
  400.     five->setGeometry(100, 130, 300, 30);  
  401.     five->show();  
  402.     spaceWidget->setGeometry(0, 0, 555, 160);  
  403.     widgetScrollArea->resize(555, 160);  
  404. }  
  405.   
  406. void SettingPanel::slotCurrentChanged(int index)  
  407. {  
  408.     contentsWidget->clear();  
  409.     scrollArea->takeWidget();  
  410.     loginWidget = NULL;  
  411.     panelWidget = NULL;  
  412.     statusWidget = NULL;  
  413.     sessionWidget = NULL;  
  414.     passwordWidget = NULL;  
  415.     qqlockWidget = NULL;  
  416.     spaceWidget = NULL;  
  417.   
  418.     widgetScrollArea = new QWidget(this);  
  419.     widgetScrollArea->setStyleSheet("background:transparent;");  
  420.     scrollArea->setWidget(widgetScrollArea);  
  421.     if (index == 0) {  
  422.         contentsWidget->addItem(tr("login"));  
  423.         contentsWidget->addItem(tr("mainpanel"));  
  424.         contentsWidget->addItem(tr("status"));  
  425.         contentsWidget->addItem(tr("session"));  
  426.         initTabOneWidget();  
  427.     }  
  428.     else if (index == 1){  
  429.         contentsWidget->addItem(tr("password"));  
  430.         contentsWidget->addItem(tr("qqlock"));  
  431.         initTabTwoWidget();  
  432.     }  
  433.     else if (index == 2) {  
  434.         contentsWidget->addItem(tr("spacepermission"));  
  435.         initTabThreeWidget();  
  436.     }  
  437.     if (contentsWidget->count() > 0) {  
  438.         contentsWidget->setCurrentRow(0);  
  439.     }  
  440. }  
  441.   
  442. void SettingPanel::slotItemClicked(QListWidgetItem *item)  
  443. {  
  444.     signFlag = true ;  
  445.     QString itemText = item->text();  
  446.     QPoint widgetPos;  
  447.     if (tabWidget->currentIndex() == 0) {  
  448.         if (itemText == tr("mainpanel")) {  
  449.             widgetPos = panelWidget->pos();  
  450.             scrollArea->verticalScrollBar()->setSliderPosition(widgetPos.y());  
  451.         }  
  452.         else if (itemText == tr("status")) {  
  453.             widgetPos = statusWidget->pos();  
  454.             scrollArea->verticalScrollBar()->setValue(widgetPos.y());  
  455.         }  
  456.         else if (itemText == tr("session")) {  
  457.             widgetPos = sessionWidget->pos();  
  458.             scrollArea->verticalScrollBar()->setValue(widgetPos.y());  
  459.         }  
  460.         else if (itemText == tr("login")) {  
  461.             widgetPos = loginWidget->pos();  
  462.             scrollArea->verticalScrollBar()->setValue(widgetPos.y());  
  463.         }  
  464.     }  
  465.     else if (tabWidget->currentIndex() == 1) {  
  466.         if (itemText == tr("password")) {  
  467.             widgetPos = passwordWidget->pos();  
  468.             scrollArea->verticalScrollBar()->setSliderPosition(widgetPos.y());  
  469.         }  
  470.         else if (itemText == tr("qqlock")) {  
  471.             widgetPos = qqlockWidget->pos();  
  472.             scrollArea->verticalScrollBar()->setValue(widgetPos.y());  
  473.         }  
  474.     }  
  475. }  
  476.   
  477. void SettingPanel::slotValueChanged(int value)  
  478. {  
  479.     if (tabWidget->currentIndex() == 0) {  
  480.         QListWidgetItem *loginItem = contentsWidget->item(0);  
  481.         QListWidgetItem *panelItem = contentsWidget->item(1);  
  482.         QListWidgetItem *statusItem = contentsWidget->item(2);  
  483.         QListWidgetItem *sessionItem = contentsWidget->item(3);  
  484.         if (!signFlag) {  
  485.             if (loginWidget && panelWidget && statusWidget && sessionWidget) {  
  486.                 if (!loginWidget->visibleRegion().isEmpty()) {  
  487.                     loginItem->setSelected(true);  
  488.                     return;  
  489.                 }  
  490.                 else {  
  491.                     loginItem->setSelected(false);  
  492.                 }  
  493.                 if (!panelWidget->visibleRegion().isEmpty()) {  
  494.                     panelItem->setSelected(true);  
  495.                     return;  
  496.                 }  
  497.                 else {  
  498.                     panelItem->setSelected(false);  
  499.                 }  
  500.                 if (!statusWidget->visibleRegion().isEmpty()) {  
  501.                     statusItem->setSelected(true);  
  502.                     return;  
  503.                 }  
  504.                 else {  
  505.                     statusItem->setSelected(false);  
  506.                 }  
  507.                 if (!sessionWidget->visibleRegion().isEmpty()) {  
  508.                     sessionItem->setSelected(true);  
  509.                     return;  
  510.                 }  
  511.                 else {  
  512.                     sessionItem->setSelected(false);  
  513.                 }  
  514.             }  
  515.         }  
  516.     }  
  517.     else if (tabWidget->currentIndex() == 1) {  
  518.         QListWidgetItem *passwordItem = contentsWidget->item(0);  
  519.         QListWidgetItem *qqlockItem = contentsWidget->item(1);  
  520.         if (!signFlag) {  
  521.             if (passwordWidget && qqlockWidget) {  
  522.                 if (!passwordWidget->visibleRegion().isEmpty()) {  
  523.                     passwordItem->setSelected(true);  
  524.                     return;  
  525.                 }  
  526.                 else {  
  527.                     passwordItem->setSelected(false);  
  528.                 }  
  529.                 if (!qqlockWidget->visibleRegion().isEmpty()) {  
  530.                     qqlockItem->setSelected(true);  
  531.                     return;  
  532.                 }  
  533.                 else {  
  534.                     qqlockItem->setSelected(false);  
  535.                 }  
  536.             }  
  537.         }  
  538.     }  
  539.     signFlag = false;  
  540. }  
  541.   
  542. void SettingPanel::paintEvent(QPaintEvent *event)  
  543. {  
  544.     QPainter painter(this);  
  545.     painter.setPen(Qt::NoPen);  
  546.     painter.setBrush(QColor("#F0F0F0"));  
  547.     painter.drawRect(this->rect());  
  548.     painter.setBrush(QColor("#069dd5"));  
  549.     painter.drawRect(rectMove);  
  550.     painter.setPen(QColor("#D7D7D7"));  
  551.     painter.drawLine(0, 70, this->width(), 70);  
  552.     QWidget::paintEvent(event);  
  553. }  
  554.   
  555. void SettingPanel::mousePressEvent(QMouseEvent *event)  
  556. {  
  557.     if(event->button() == Qt::LeftButton && rectMove.contains(event->pos())) {  
  558.         mousePress = true;  
  559.     }  
  560.     movePoint = event->globalPos() - pos();  
  561.     QWidget::mousePressEvent(event);  
  562. }  
  563.   
  564. void SettingPanel::mouseReleaseEvent(QMouseEvent *event)  
  565. {  
  566.     mousePress = false;  
  567.     QWidget::mouseReleaseEvent(event);  
  568. }  
  569.   
  570. void SettingPanel::mouseMoveEvent(QMouseEvent *event)  
  571. {  
  572.     if(mousePress) {  
  573.         QPoint movePos = event->globalPos();  
  574.         move(movePos - movePoint);  
  575.     }  
  576.     QWidget::mouseMoveEvent(event);  
  577. }  

  • 编译运行


三、总结

(1)相应的代码已上传到csdn:http://download.csdn.net/detail/taiyang1987912/9330019
(2)未设计功能,界面还有很多不满意的地方,应用到项目中可以自行调整。
(3)若有建议,请留言,在此先感谢!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多