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. QProgressBar, custom text position through stylesheet?
Forum Updated to NodeBB v4.3 + New Features

QProgressBar, custom text position through stylesheet?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 436 Views 2 Watching
  • 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    I would like to position my QProgressBar text within the current chunk. I can compute the required offset myself, but it seems the label position can only be one of (left, center, right). Is there a way to position it with more granularity?

    Bonus question: can we style the last chunk and give it a different color for instance?

    Thanks a lot

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JulienMaille
      wrote on last edited by
      #2

      Anyone has a clue?

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        I dont think its possible using stylesheets since it seems the text is using TextAligemnt and not an x,y pos.
        I think you can do it using a QProxyStyle to override how it draws the text.

        It goes

          case CE_ProgressBar:
                if (const QStyleOptionProgressBar *pb
                        = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
                    QStyleOptionProgressBar subopt = *pb;
                    subopt.rect = subElementRect(SE_ProgressBarGroove, pb, widget);
                    proxy()->drawControl(CE_ProgressBarGroove, &subopt, p, widget);
                    subopt.rect = subElementRect(SE_ProgressBarContents, pb, widget);
                    proxy()->drawControl(CE_ProgressBarContents, &subopt, p, widget);
                    if (pb->textVisible) {
                        subopt.rect = subElementRect(SE_ProgressBarLabel, pb, widget);
                        proxy()->drawControl(CE_ProgressBarLabel, &subopt, p, widget);
                    }
                }
        

        So its very likely you can overrride drawControl and for CE_ProgressBarLabel draw the text where you want.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JulienMaille
          wrote on last edited by
          #4

          Ok, thanks for the insight.

          1 Reply Last reply
          0

          • Login

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