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. Qt Image on label
Forum Updated to NodeBB v4.3 + New Features

Qt Image on label

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 2 Posters 4.8k Views 1 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #6

    ok. thank you for code.
    So even with this code, it sometimes is way bigger than 12 points?

    I wonder if some of the images makes setPointSize scale.
    Can you try with
    void QFont::setPixelSize(int pixelSize)
    and see if it still makes big text sometimes.
    Then we know why it happens.

    G 1 Reply Last reply
    1
    • G Offline
      G Offline
      Gayathri
      wrote on last edited by
      #7

      Ok i will try that

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

        oh I forgot to ask.
        Can you make it draw big text each time if u use the image that does it?
        I mean, is it repeatable ?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Gayathri
          wrote on last edited by
          #9

          yes every time i use that background pic ..it is big !

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Gayathri
            wrote on last edited by
            #10

            Hi. SetPixel size worked !!!!!! Could you explain to me why is that so ?

            mrjjM 1 Reply Last reply
            0
            • mrjjM mrjj

              ok. thank you for code.
              So even with this code, it sometimes is way bigger than 12 points?

              I wonder if some of the images makes setPointSize scale.
              Can you try with
              void QFont::setPixelSize(int pixelSize)
              and see if it still makes big text sometimes.
              Then we know why it happens.

              G Offline
              G Offline
              Gayathri
              wrote on last edited by
              #11

              @mrjj

              Setpixel size worked ! ... Could u explain as to why this worked

              Also i have another question.

              Now i have textwrap for my text in drawtext. But it does go out of view. Is it possible to change font to fit the size of the space i have ???? . Changing font dynamically depending on the size of the dialogue and the space

              1 Reply Last reply
              0
              • G Gayathri

                Hi. SetPixel size worked !!!!!! Could you explain to me why is that so ?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #12

                @Gayathri
                Super.
                Well setPointSize is relative to resolution of the device/surface.
                so when you say 12. it will try to make that look like 12 across many different
                screens. Its call device independent.

                setPixelSizeon the other hand just use the value you give it so
                on other screen, it might look much smaller.

                so I think setPointSize somehow thinks that your big image is much higher res
                and then try to help you scale the font.

                ++ change font to fit the size
                Well you can code it yes.
                using
                QFontMetrics fm(myFont);
                int width=fm.width(str);
                you can get size info about what you draw
                so you can check if it fits inside the rect you have.
                if NOT, then you can reduce font size and try again
                until it fits.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  Gayathri
                  wrote on last edited by
                  #13

                  Thanks a lot @mrjj. You were of great help !

                  mrjjM 1 Reply Last reply
                  0
                  • G Gayathri

                    Thanks a lot @mrjj. You were of great help !

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    @Gayathri
                    Super. Please mark as solved if possible.

                    Final note:
                    if you make a loop to find font size then make sure
                    to make a counter guard to exit if looping too many times.
                    while ( TestSize(FontSize,str)==false & count++ < 100) {
                    FontSize--;
                    }
                    So you dont hang your app if u ever get a text that just cannot fit :)

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      Gayathri
                      wrote on last edited by
                      #15

                      sure i will ...thanks mrjj

                      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