当前位置 博文首页 > 木木木 的博客:Qt开发之路11---按钮QPushButton

    木木木 的博客:Qt开发之路11---按钮QPushButton

    作者:[db:作者] 时间:2021-08-21 10:06

    一:QPushButton创建

        QPushButton *btn = new QPushButton(this);//新建按钮对象
        btn->resize(50,50);//设置按钮尺寸
        btn->move(100,100);//设置显示的位置
        btn->setText("close");//设置显示文字
    
        connect(btn,SIGNAL(clicked(bool)),this,SLOT(close()));//连接信号槽,点击按钮,关闭窗口
    

    二:QPushButton样式表

        btn->setStyleSheet("QPushButton{"//正常状态样式
                                "background-color:rgba(250,0,0,1);"//背景色(也可以设置图片)
                                "border-width:2px;"                     //边框宽度像素
                                "border-radius:5px;"                    //边框圆角半径像素
                                "border-color:rgba(0,250,0,1);"    //边框颜色
                                "font-size:16px;"                       //字体,字体大小
                                "color:rgba(41,48,59,1);"               //字体颜色
                                "}"
                                "QPushButton:pressed{"//鼠标按下样式
                                "background-color:rgba(0,250,0,1);"
                                "border-color:rgba(0,0,255,1);"
                                "border-style:inset;"
                                "color:rgba(255,255,255,1);"
                                "}"
                                "QPushButton:hover{"//鼠标悬停样式
                                "background-color:rgba(0,0,255,1);"
                                "border-color:rgba(255,255,255,0);"
                                "color:rgba(255,255,255,1);"
                                "}");
    

    三:QPushButton设置不可点击状态

    btn->setEnabled(false);
    

    上一篇:Qt开发之路10—文件对话框QFileDialog
    下一篇:Qt开发之路12—QLabel显示文字、图片、动画

    cs