Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to design a QPushButton with progress ?
Forum Updated to NodeBB v4.3 + New Features

How to design a QPushButton with progress ?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 Posters 4.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    I want to show download progress on QPushButton via background-color percent.
    Demo(JQUERY+CSS3) : http://www.xwcms.net/webAnnexImages/fileAnnex/20140122/88077/index.html

    alt text

    https://github.com/sonichy

    jsulmJ joeQJ D 3 Replies Last reply
    0
    • sonichyS sonichy

      I want to show download progress on QPushButton via background-color percent.
      Demo(JQUERY+CSS3) : http://www.xwcms.net/webAnnexImages/fileAnnex/20140122/88077/index.html

      alt text

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sonichy You can inherit from QPushButton and overwrite http://doc.qt.io/qt-5/qwidget.html#paintEvent where you then paint manually.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • sonichyS sonichy

        I want to show download progress on QPushButton via background-color percent.
        Demo(JQUERY+CSS3) : http://www.xwcms.net/webAnnexImages/fileAnnex/20140122/88077/index.html

        alt text

        joeQJ Offline
        joeQJ Offline
        joeQ
        wrote on last edited by joeQ
        #3

        @sonichy Hi,friend,welcome.

        I saw the image has some Chinese words. so i used Chinese to reply.

        Chinese version

        如果是静态的背景样式的话, 可以使用设置 QStyle 字符串或者直接显示背景图像,这个您应该知道。

        对于动态的样式,多数是重载QWidget::paintEvent函数,一点一点绘制而成的。

        或者,子类化QWidget, 重写一些鼠标事件和绘制事件,也就是自定义控件了。

        English version

        If it is a static background style, you can use the set QStyle string or directly display the background image, which you should know.

        For dynamic styles, most of them are overloaded with the QWidget :: paintEvent function, which is drawn a little bit.

        Or, subclass QWidget, rewrite some mouse events and draw events, that is, custom controls.

        ^_^

        Just do it!

        BjornWB 1 Reply Last reply
        0
        • sonichyS sonichy

          I want to show download progress on QPushButton via background-color percent.
          Demo(JQUERY+CSS3) : http://www.xwcms.net/webAnnexImages/fileAnnex/20140122/88077/index.html

          alt text

          D Offline
          D Offline
          Devopia53
          wrote on last edited by Devopia53
          #4

          @sonichy

          If you want to use CSS, see the following my example.

          auto            timer = new QTimer(this);
          static float    value = 0.0f;
          
          connect(timer, &QTimer::timeout, [&, timer]{
              value += 0.1f;
              ui->pushButton->setStyleSheet(QString("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0,"
                                                    "stop:0 rgba(230, 103, 192, 255), stop:%1 rgba(230, 103, 192, 255),"
                                                    "stop:%2 rgba(79, 179, 228, 255), stop:1 rgba(79, 179, 228, 255));")
                                            .arg(value-0.001f)
                                            .arg(value));
              if (value >= 1.0f) {
                  timer->stop();
                  timer->deleteLater();
              }
          });
          timer->start(1000);
          
          sonichyS 1 Reply Last reply
          6
          • joeQJ joeQ

            @sonichy Hi,friend,welcome.

            I saw the image has some Chinese words. so i used Chinese to reply.

            Chinese version

            如果是静态的背景样式的话, 可以使用设置 QStyle 字符串或者直接显示背景图像,这个您应该知道。

            对于动态的样式,多数是重载QWidget::paintEvent函数,一点一点绘制而成的。

            或者,子类化QWidget, 重写一些鼠标事件和绘制事件,也就是自定义控件了。

            English version

            If it is a static background style, you can use the set QStyle string or directly display the background image, which you should know.

            For dynamic styles, most of them are overloaded with the QWidget :: paintEvent function, which is drawn a little bit.

            Or, subclass QWidget, rewrite some mouse events and draw events, that is, custom controls.

            ^_^

            BjornWB Offline
            BjornWB Offline
            BjornW
            wrote on last edited by
            #5

            @joeQ said in How to design a QPushButton with progress ?:

            @sonichy Hi,friend,welcome.

            I saw the image has some Chinese words. so i used Chinese to reply.

            如果是静态的背景样式的话, 可以使用设置 QStyle 字符串或者直接显示背景图像,这个您应该知道。

            对于动态的样式,多数是重载QWidget::paintEvent函数,一点一点绘制而成的。

            或者,子类化QWidget, 重写一些鼠标事件和绘制事件,也就是自定义控件了。

            As much as I love seeing some chinese text, I think it is good if replies are kept english for future reference ^_^

            joeQJ 1 Reply Last reply
            1
            • BjornWB BjornW

              @joeQ said in How to design a QPushButton with progress ?:

              @sonichy Hi,friend,welcome.

              I saw the image has some Chinese words. so i used Chinese to reply.

              如果是静态的背景样式的话, 可以使用设置 QStyle 字符串或者直接显示背景图像,这个您应该知道。

              对于动态的样式,多数是重载QWidget::paintEvent函数,一点一点绘制而成的。

              或者,子类化QWidget, 重写一些鼠标事件和绘制事件,也就是自定义控件了。

              As much as I love seeing some chinese text, I think it is good if replies are kept english for future reference ^_^

              joeQJ Offline
              joeQJ Offline
              joeQ
              wrote on last edited by
              #6

              @BjornW

              (^▽^), Thank u, good suggestion. Most of I use English. This time, I guessed the person asked question is Chinese. so ...

              Just do it!

              jsulmJ 1 Reply Last reply
              2
              • joeQJ joeQ

                @BjornW

                (^▽^), Thank u, good suggestion. Most of I use English. This time, I guessed the person asked question is Chinese. so ...

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @joeQ Asking person yes, but many others here not. For them (including me) it would be hard/impossible to follow the discussion and to contribute if it is in Chinese.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                joeQJ 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @joeQ Asking person yes, but many others here not. For them (including me) it would be hard/impossible to follow the discussion and to contribute if it is in Chinese.

                  joeQJ Offline
                  joeQJ Offline
                  joeQ
                  wrote on last edited by
                  #8

                  @jsulm
                  Yes, you are right. I am sorry, ignoring other people.

                  Just do it!

                  1 Reply Last reply
                  2
                  • D Devopia53

                    @sonichy

                    If you want to use CSS, see the following my example.

                    auto            timer = new QTimer(this);
                    static float    value = 0.0f;
                    
                    connect(timer, &QTimer::timeout, [&, timer]{
                        value += 0.1f;
                        ui->pushButton->setStyleSheet(QString("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0,"
                                                              "stop:0 rgba(230, 103, 192, 255), stop:%1 rgba(230, 103, 192, 255),"
                                                              "stop:%2 rgba(79, 179, 228, 255), stop:1 rgba(79, 179, 228, 255));")
                                                      .arg(value-0.001f)
                                                      .arg(value));
                        if (value >= 1.0f) {
                            timer->stop();
                            timer->deleteLater();
                        }
                    });
                    timer->start(1000);
                    
                    sonichyS Offline
                    sonichyS Offline
                    sonichy
                    wrote on last edited by sonichy
                    #9

                    @Devopia53
                    It works great!

                    https://github.com/sonichy

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved