资源简介

采用qt5.9vs版编译 定制QPushButton样式 弹出省市区三级选择菜单

资源截图

代码片段和文件信息

#include “citybutton.h“
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

CityButton::CityButton(QWidget *parent) :
    QPushButton(parent)
    m_bDataIsSet(false)
    m_bPosIsChecked(false)
{
    // button样式
    this->setstyleSheet(“QPushButton{“
                                “border:1px solid #4edeff;“
                                “background-color:#11597e;“
                                “font: 75 9pt \“微软雅黑\“;“
                                “color:#ffffff;}“
                        “QPushButton:hover{“
                                “background-color:#1983bd;}“);

    QHBoxLayout* pLayout = new QHBoxLayout();
    pLayout->setContentsMargins(0040);

    m_pTextLabel = new QLabel;
    m_pTextLabel->setstyleSheet(“QLabel{border:none;margin:3px;background-color:transparent;font: 75 9pt \“微软雅黑\“;color:#ffffff;}“);
    QLabel* pLabelImage = new QLabel();
    pLabelImage->setstyleSheet(“QLabel{border:none;margin:3px;background-color:transparent;}“);
    pLabelImage->setPixmap(QPixmap(“:/images/down-03.png“));
    pLayout->addWidget(m_pTextLabel);
    pLayout->addStretch();
    pLayout->addWidget(pLabelImage);
    this->setLayout(pLayout);

    m_pTextLabel->setText(QStringLiteral(“请选择“));

    connect(thisSIGNAL(clicked(bool))thisSLOT(onSlotBtnClicked()));


    //m_pMainWidget = new QWidget(Q_NULLPTR);
    m_pMainWidget = new MyPopupWidget(Q_NULLPTR);
    connect(m_pMainWidgetSIGNAL(mouseLeaved())thisSLOT(onSlotMouseLeaved()));
    m_pCityWidget = new CityTableWidget(m_pMainWidget);
    m_pAreaWidget = new CityTableWidget(m_pMainWidget);
    m_pMainWidget->setWindowFlags(Qt::WindowStaysOnTopHint);
    m_pMainWidget->setWindowFlags(Qt::framelessWindowHint);
    m_pMainWidget->setAttribute(Qt::WA_TranslucentBackground);
    m_pMainWidget->setVisible(false);
    m_pAreaWidget->setVisible(false);

    connect(m_pCityWidgetSIGNAL(itemClicked(Region*))thisSLOT(onSlotAreaBtnClicked(Region*)));
    connect(m_pCityWidgetSIGNAL(itemGetFocus(Region*intint))thisSLOT(onSlotAreaBtnGetFocus(Region*intint)));
    connect(m_pAreaWidgetSIGNAL(itemClicked(Region*))thisSLOT(onSlotAreaBtnClicked(Region*)));
}

void CityButton::onSlotMouseLeaved()
{
    if(m_pMainWidget->isVisible())
    {
        m_pMainWidget->setVisible(false);
    }
}

static QPoint getGlobalPos(QWidget* widget)
{
    if(0 == widget)
    {
        return QPoint(-1-1);
    }
    QPoint point = widget->pos();
    QWidget* parent = widget->parentWidget();
    while(0 != parent)
    {
        point.setX(point.x() + parent->pos().x());
        point.setY(point.y() + parent->pos().y());
        parent = parent->parentWidget();
    }
    return point;
}

void CityButton::setData(Region re)
{
    m_areaData = re;
    m_pCityWidget->setData(QStringLiteral(“市级“)&re);
    m_bDa

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      10918  2017-11-17 16:18  CityButton\citybutton.cpp

     文件       2692  2017-11-21 14:17  CityButton\citybutton.h

     文件       1133  2017-11-10 15:02  CityButton\CityButton.pro

     文件      23452  2017-11-21 14:16  CityButton\CityButton.pro.user

     文件      23851  2017-11-13 12:16  CityButton\CityButton.pro.user.cf9c797

     文件       1117  2017-11-08 15:26  CityButton\images\btn-right.png

     文件       1040  2017-10-25 15:55  CityButton\images\down-01.png

     文件       1048  2017-10-26 09:22  CityButton\images\down-02.png

     文件       1031  2017-10-25 15:39  CityButton\images\down-03.png

     文件       1037  2017-10-25 15:55  CityButton\images\up-01.png

     文件       1045  2017-10-26 09:22  CityButton\images\up-02.png

     文件        256  2017-11-13 09:51  CityButton\main.cpp

     文件       2097  2017-11-13 09:51  CityButton\mainwidget.cpp

     文件        308  2017-11-10 15:05  CityButton\mainwidget.h

     文件       1544  2017-11-13 10:59  CityButton\mainwidget.ui

     文件        305  2017-11-08 15:27  CityButton\resource.qrc

     目录          0  2017-11-13 13:46  CityButton\images

     目录          0  2017-11-21 14:17  CityButton

----------- ---------  ---------- -----  ----

                72874                    18


评论

共有 条评论