qt實作類別似qq的陰影表單,qtqq陰影表單

來源:互聯網
上載者:User

qt實作類別似qq的陰影表單,qtqq陰影表單

#ifndef BFWIDGET_H#define BFWIDGET_H#include <QWidget>#include <QMouseEvent>#include <QResizeEvent>/** * 視窗可以拖動 * 視窗增加陰影製作效果 * @brief The BFWidget class */class BFWidget : public QWidget{    Q_OBJECTpublic:    explicit BFWidget(QWidget *parent = 0);    /**     * 重寫空間排版設定     * 把空間排版到central_widget上面     * @brief setLayout     * @param layout     */    void setLayout(QLayout * layout);signals:public slots:protected:    void mousePressEvent(QMouseEvent *event);    void mouseReleaseEvent(QMouseEvent *event);    void mouseMoveEvent(QMouseEvent *event);    //void resizeEvent(QResizeEvent *event);private:    //顯示內容的地區    QWidget     *central_widget;    QPoint move_point; //移動的距離    bool mouse_press; //按下滑鼠左鍵};#endif // BFWIDGET_H

<pre name="code" class="cpp">#include <QBoxLayout>#include <QPalette>#include <QGraphicsDropShadowEffect>#include <QDebug>#include <QSizePolicy>#include "bfwidget.h"BFWidget::BFWidget(QWidget *parent) :    QWidget(parent){    setWindowFlags(Qt::FramelessWindowHint);    setAttribute(Qt::WA_TranslucentBackground);    central_widget = new QWidget();    central_widget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); ////水平方向和垂直方向任意伸展    QPalette palette;    palette.setBrush(QPalette::Background,QBrush(QColor(255,255,255)));    central_widget->setPalette(palette);    central_widget->setAutoFillBackground(true);    QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect();    shadow_effect->setBlurRadius(10.0);    shadow_effect->setColor(QColor(0, 0, 0, 100));    shadow_effect->setOffset(1.0);    central_widget->setGraphicsEffect(shadow_effect);    QVBoxLayout * main_layout = new QVBoxLayout();    main_layout->addWidget(central_widget, Qt::AlignCenter);    main_layout->addSpacing(0);    main_layout->setContentsMargins(5,5,5,5);    QWidget::setLayout(main_layout);}void BFWidget::setLayout(QLayout *layout){    central_widget->setLayout(layout);}void BFWidget::mousePressEvent( QMouseEvent * event ){    //只能是滑鼠左鍵移動和改變大小    if(event->button() == Qt::LeftButton)    {        mouse_press = true;    }    //視窗移動距離    move_point = event->globalPos() - pos();}void BFWidget::mouseReleaseEvent(QMouseEvent *){    mouse_press = false;}void BFWidget::mouseMoveEvent(QMouseEvent *event){    //移動視窗    if(mouse_press)    {        QPoint move_pos = event->globalPos();        move(move_pos - move_point);    }}//void BFWidget::resizeEvent(QResizeEvent *event)//{//    QSize size = event->size();//    central_widget->setGeometry(5, 5, size.width() - 10, size.height() - 10);//    qDebug() << central_widget->rect();//}




qt一個登入表單中實現與qq一樣記錄使用者名稱與密碼的功可以

樓主要建一個檔案來儲存密碼的值和是否記錄密碼的值,在下一次開啟的時候(在這個Dialog的showEvent函數中添加代碼)根據是否記錄密碼的值來初始化passWordLineEdit和jiluCheckBox的
值,儲存可以用QDataStream來實現。QDeam裡面有執行個體。樓主(^ω^)加油
 
QT下的表單之間的傳值怎實現?教

使用全域變數啊,或者通過訊號-槽機制
把參數放到訊號和槽的參數中,傳遞過去就行了

給點分吧。。。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.