91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Qt怎么設置按鈕樣式

發布時間:2021-12-15 10:27:07 來源:億速云 閱讀:579 作者:iii 欄目:互聯網科技

本篇內容主要講解“Qt怎么設置按鈕樣式”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Qt怎么設置按鈕樣式”吧!

函數名

    //設置按鈕樣式
    static QString setPushButtonQss(QPushButton *btn,                               //按鈕對象
                                    int radius = 5,                                 //圓角半徑
                                    int padding = 8,                                //間距
                                    const QString &normalColor = "#34495E",         //正常顏色
                                    const QString &normalTextColor = "#FFFFFF",     //文字顏色
                                    const QString &hoverColor = "#4E6D8C",          //懸停顏色
                                    const QString &hoverTextColor = "#F0F0F0",      //懸停文字顏色
                                    const QString &pressedColor = "#2D3E50",        //按下顏色
                                    const QString &pressedTextColor = "#B8C6D1");   //按下文字顏色
    //設置文本框樣式
    static QString setLineEditQss(QLineEdit *txt,                                   //文本框對象
                                  int radius = 3,                                   //圓角半徑
                                  int borderWidth = 2,                              //邊框大小
                                  const QString &normalColor = "#DCE4EC",           //正常顏色
                                  const QString &focusColor = "#34495E");           //選中顏色
    //設置進度條樣式
    static QString setProgressBarQss(QProgressBar *bar,
                                     int barHeight = 8,                             //進度條高度
                                     int barRadius = 5,                             //進度條半徑
                                     int fontSize = 9,                              //文字字號
                                     const QString &normalColor = "#E8EDF2",        //正常顏色
                                     const QString &chunkColor = "#E74C3C");        //進度顏色
    //設置滑塊條樣式
    static QString setSliderQss(QSlider *slider,                                    //滑動條對象
                                int sliderHeight = 8,                               //滑動條高度
                                const QString &normalColor = "#E8EDF2",             //正常顏色
                                const QString &grooveColor = "#1ABC9C",             //滑塊顏色
                                const QString &handleBorderColor = "#1ABC9C",       //指示器邊框顏色
                                const QString &handleColor = "#FFFFFF",             //指示器顏色
                                const QString &textColor = "#000000");              //文字顏色
    //設置單選框樣式
    static QString setRadioButtonQss(QRadioButton *rbtn,                            //單選框對象
                                     int indicatorRadius = 8,                       //指示器圓角角度
                                     const QString &normalColor = "#D7DBDE",        //正常顏色
                                     const QString &checkColor = "#34495E");        //選中顏色
    //設置滾動條樣式
    static QString setScrollBarQss(QWidget *scroll,                                 //滾動條對象
                                   int radius = 6,                                  //圓角角度
                                   int min = 120,                                   //指示器最小長度
                                   int max = 12,                                    //滾動條最大長度
                                   const QString &bgColor = "#606060",              //背景色
                                   const QString &handleNormalColor = "#34495E",    //指示器正常顏色
                                   const QString &handleHoverColor = "#1ABC9C",     //指示器懸停顏色
                                   const QString &handlePressedColor = "#E74C3C");  //指示器按下顏色

函數體

QString QUIHelper::setPushButtonQss(QPushButton *btn, int radius, int padding,
                                    const QString &normalColor,
                                    const QString &normalTextColor,
                                    const QString &hoverColor,
                                    const QString &hoverTextColor,
                                    const QString &pressedColor,
                                    const QString &pressedTextColor)
{
    QStringList list;
    list.append(QString("QPushButton{border-style:none;padding:%1px;border-radius:%2px;color:%3;background:%4;}")
                .arg(padding).arg(radius).arg(normalTextColor).arg(normalColor));
    list.append(QString("QPushButton:hover{color:%1;background:%2;}")
                .arg(hoverTextColor).arg(hoverColor));
    list.append(QString("QPushButton:pressed{color:%1;background:%2;}")
                .arg(pressedTextColor).arg(pressedColor));

    QString qss = list.join("");
    btn->setStyleSheet(qss);
    return qss;
}

QString QUIHelper::setLineEditQss(QLineEdit *txt, int radius, int borderWidth,
                                  const QString &normalColor,
                                  const QString &focusColor)
{
    QStringList list;
    list.append(QString("QLineEdit{border-style:none;padding:3px;border-radius:%1px;border:%2px solid %3;}")
                .arg(radius).arg(borderWidth).arg(normalColor));
    list.append(QString("QLineEdit:focus{border:%1px solid %2;}")
                .arg(borderWidth).arg(focusColor));

    QString qss = list.join("");
    txt->setStyleSheet(qss);
    return qss;
}

QString QUIHelper::setProgressBarQss(QProgressBar *bar, int barHeight,
                                     int barRadius, int fontSize,
                                     const QString &normalColor,
                                     const QString &chunkColor)
{

    QStringList list;
    list.append(QString("QProgressBar{font:%1pt;background:%2;max-height:%3px;border-radius:%4px;text-align:center;border:1px solid %2;}")
                .arg(fontSize).arg(normalColor).arg(barHeight).arg(barRadius));
    list.append(QString("QProgressBar:chunk{border-radius:%2px;background-color:%1;}")
                .arg(chunkColor).arg(barRadius));

    QString qss = list.join("");
    bar->setStyleSheet(qss);
    return qss;
}

QString QUIHelper::setSliderQss(QSlider *slider, int sliderHeight,
                                const QString &normalColor,
                                const QString &grooveColor,
                                const QString &handleBorderColor,
                                const QString &handleColor,
                                const QString &textColor)
{
    int sliderRadius = sliderHeight / 2;
    int handleSize = (sliderHeight * 3) / 2 + (sliderHeight / 5);
    int handleRadius = handleSize / 2;
    int handleOffset = handleRadius / 2;

    QStringList list;
    int handleWidth = handleSize + sliderHeight / 5 - 1;
    list.append(QString("QSlider::horizontal{min-height:%1px;color:%2;}").arg(sliderHeight * 2).arg(textColor));
    list.append(QString("QSlider::groove:horizontal{background:%1;height:%2px;border-radius:%3px;}")
                .arg(normalColor).arg(sliderHeight).arg(sliderRadius));
    list.append(QString("QSlider::add-page:horizontal{background:%1;height:%2px;border-radius:%3px;}")
                .arg(normalColor).arg(sliderHeight).arg(sliderRadius));
    list.append(QString("QSlider::sub-page:horizontal{background:%1;height:%2px;border-radius:%3px;}")
                .arg(grooveColor).arg(sliderHeight).arg(sliderRadius));
    list.append(QString("QSlider::handle:horizontal{width:%3px;margin-top:-%4px;margin-bottom:-%4px;border-radius:%5px;"
                        "background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,stop:0.6 %1,stop:0.8 %2);}")
                .arg(handleColor).arg(handleBorderColor).arg(handleWidth).arg(handleOffset).arg(handleRadius));

    //偏移一個像素
    handleWidth = handleSize + sliderHeight / 5;
    list.append(QString("QSlider::vertical{min-width:%1px;color:%2;}").arg(sliderHeight * 2).arg(textColor));
    list.append(QString("QSlider::groove:vertical{background:%1;width:%2px;border-radius:%3px;}")
                .arg(normalColor).arg(sliderHeight).arg(sliderRadius));
    list.append(QString("QSlider::add-page:vertical{background:%1;width:%2px;border-radius:%3px;}")
                .arg(grooveColor).arg(sliderHeight).arg(sliderRadius));
    list.append(QString("QSlider::sub-page:vertical{background:%1;width:%2px;border-radius:%3px;}")
                .arg(normalColor).arg(sliderHeight).arg(sliderRadius));
    list.append(QString("QSlider::handle:vertical{height:%3px;margin-left:-%4px;margin-right:-%4px;border-radius:%5px;"
                        "background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,stop:0.6 %1,stop:0.8 %2);}")
                .arg(handleColor).arg(handleBorderColor).arg(handleWidth).arg(handleOffset).arg(handleRadius));

    QString qss = list.join("");
    slider->setStyleSheet(qss);
    return qss;
}

QString QUIHelper::setRadioButtonQss(QRadioButton *rbtn, int indicatorRadius,
                                     const QString &normalColor,
                                     const QString &checkColor)
{
    int indicatorWidth = indicatorRadius * 2;

    QStringList list;
    list.append(QString("QRadioButton::indicator{border-radius:%1px;width:%2px;height:%2px;}")
                .arg(indicatorRadius).arg(indicatorWidth));
    list.append(QString("QRadioButton::indicator::unchecked{background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,"
                        "stop:0.6 #FFFFFF,stop:0.7 %1);}").arg(normalColor));
    list.append(QString("QRadioButton::indicator::checked{background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,"
                        "stop:0 %1,stop:0.3 %1,stop:0.4 #FFFFFF,stop:0.6 #FFFFFF,stop:0.7 %1);}").arg(checkColor));

    QString qss = list.join("");
    rbtn->setStyleSheet(qss);
    return qss;
}

QString QUIHelper::setScrollBarQss(QWidget *scroll, int radius, int min, int max,
                                   const QString &bgColor,
                                   const QString &handleNormalColor,
                                   const QString &handleHoverColor,
                                   const QString &handlePressedColor)
{
    //滾動條離背景間隔
    int padding = 0;

    QStringList list;

    //handle:指示器,滾動條拉動部分 add-page:滾動條拉動時增加的部分 sub-page:滾動條拉動時減少的部分 add-line:遞增按鈕 sub-line:遞減按鈕

    //橫向滾動條部分
    list.append(QString("QScrollBar:horizontal{background:%1;padding:%2px;border-radius:%3px;min-height:%4px;max-height:%4px;}")
                .arg(bgColor).arg(padding).arg(radius).arg(max));
    list.append(QString("QScrollBar::handle:horizontal{background:%1;min-width:%2px;border-radius:%3px;}")
                .arg(handleNormalColor).arg(min).arg(radius));
    list.append(QString("QScrollBar::handle:horizontal:hover{background:%1;}")
                .arg(handleHoverColor));
    list.append(QString("QScrollBar::handle:horizontal:pressed{background:%1;}")
                .arg(handlePressedColor));
    list.append(QString("QScrollBar::add-page:horizontal{background:none;}"));
    list.append(QString("QScrollBar::sub-page:horizontal{background:none;}"));
    list.append(QString("QScrollBar::add-line:horizontal{background:none;}"));
    list.append(QString("QScrollBar::sub-line:horizontal{background:none;}"));

    //縱向滾動條部分
    list.append(QString("QScrollBar:vertical{background:%1;padding:%2px;border-radius:%3px;min-width:%4px;max-width:%4px;}")
                .arg(bgColor).arg(padding).arg(radius).arg(max));
    list.append(QString("QScrollBar::handle:vertical{background:%1;min-height:%2px;border-radius:%3px;}")
                .arg(handleNormalColor).arg(min).arg(radius));
    list.append(QString("QScrollBar::handle:vertical:hover{background:%1;}")
                .arg(handleHoverColor));
    list.append(QString("QScrollBar::handle:vertical:pressed{background:%1;}")
                .arg(handlePressedColor));
    list.append(QString("QScrollBar::add-page:vertical{background:none;}"));
    list.append(QString("QScrollBar::sub-page:vertical{background:none;}"));
    list.append(QString("QScrollBar::add-line:vertical{background:none;}"));
    list.append(QString("QScrollBar::sub-line:vertical{background:none;}"));

    QString qss = list.join("");
    scroll->setStyleSheet(qss);
    return qss;
}

到此,相信大家對“Qt怎么設置按鈕樣式”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

qt
AI

昌吉市| 永川市| 巩义市| 揭东县| 囊谦县| 固原市| 纳雍县| 屏边| 淅川县| 平舆县| 辽阳县| 旅游| 阳新县| 云林县| 当阳市| 礼泉县| 文成县| 虞城县| 安岳县| 景东| 广德县| 沂水县| 开远市| 原平市| 郓城县| 长岛县| 潜山县| 榆社县| 山西省| 台中县| 齐齐哈尔市| 北安市| 宕昌县| 通海县| 淅川县| 咸阳市| 孙吴县| 潼关县| 临城县| 邛崃市| 靖宇县|