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. Circle user avatar issue
Forum Updated to NodeBB v4.3 + New Features

Circle user avatar issue

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 3 Posters 7.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.
  • M mrjj
    27 Jan 2018, 13:55

    Ah so user will bring his own avatar image ?

    C Offline
    C Offline
    Cobra91151
    wrote on 27 Jan 2018, 13:55 last edited by
    #18

    @mrjj

    Yes.

    M 1 Reply Last reply 27 Jan 2018, 13:56
    0
    • C Cobra91151
      27 Jan 2018, 13:55

      @mrjj

      Yes.

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 27 Jan 2018, 13:56 last edited by
      #19

      @Cobra91151
      Ok, then painting yourself seems better :)
      What was wrong with the paintEvent + scaled + drawEllipse ?
      since you are now looking into masks

      C 1 Reply Last reply 27 Jan 2018, 14:11
      0
      • M mrjj
        27 Jan 2018, 13:56

        @Cobra91151
        Ok, then painting yourself seems better :)
        What was wrong with the paintEvent + scaled + drawEllipse ?
        since you are now looking into masks

        C Offline
        C Offline
        Cobra91151
        wrote on 27 Jan 2018, 14:11 last edited by
        #20

        @mrjj

        I draws the image but not rounds it.

        void AccountImage::paintEvent(QPaintEvent *event)
        {
            QPixmap pixmap(":/Icon/default_avatar.png");
            QPixmap scaled = pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
            QBrush brush(scaled);
            QPainter painter(this);
            painter.setRenderHint(QPainter::Antialiasing);
            painter.setBrush(brush);
            painter.drawPixmap(0, 0, scaled);
            QLabel::paintEvent(event);
        }
        

        alt text

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 27 Jan 2018, 14:11 last edited by mrjj
          #21

          Why not ?
          just need the
          painter.drawEllipse(0, 0, scaled.width(), scaled.height());
          after
          painter.drawPixmap(0, 0, scaled);

          C 1 Reply Last reply 27 Jan 2018, 14:13
          0
          • M mrjj
            27 Jan 2018, 14:11

            Why not ?
            just need the
            painter.drawEllipse(0, 0, scaled.width(), scaled.height());
            after
            painter.drawPixmap(0, 0, scaled);

            C Offline
            C Offline
            Cobra91151
            wrote on 27 Jan 2018, 14:13 last edited by Cobra91151
            #22

            @mrjj

            drawPixmap is draws the pixmap, not circle. What method I should use to get image circle?

            M 1 Reply Last reply 27 Jan 2018, 14:13
            0
            • C Cobra91151
              27 Jan 2018, 14:13

              @mrjj

              drawPixmap is draws the pixmap, not circle. What method I should use to get image circle?

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 27 Jan 2018, 14:13 last edited by
              #23

              @Cobra91151
              as before. drawEllipse

              C 1 Reply Last reply 27 Jan 2018, 14:19
              0
              • M mrjj
                27 Jan 2018, 14:13

                @Cobra91151
                as before. drawEllipse

                C Offline
                C Offline
                Cobra91151
                wrote on 27 Jan 2018, 14:19 last edited by Cobra91151
                #24

                @mrjj

                Code:

                void AccountImage::paintEvent(QPaintEvent *event)
                {
                    QPixmap pixmap(":/Icon/default_avatar.png");
                    QPixmap scaled = pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                    QBrush brush(scaled);
                    QPainter painter(this);
                    painter.setRenderHint(QPainter::Antialiasing);
                    painter.setBrush(brush);
                    painter.drawPixmap(0, 0, scaled);
                    painter.drawEllipse(0, 0, scaled.width(), scaled.height());
                    QLabel::paintEvent(event);
                }
                

                0_1517062687531_2018-01-27_161733.png

                Still image is not fully in a circle.

                Update:
                It looks better here:

                0_1517062937546_2018-01-27_162205.png

                void AccountImage::paintEvent(QPaintEvent *event)
                {
                    QPixmap pixmap(":/Icon/default_avatar.png");
                    QBrush brush(pixmap);
                    QPainter painter(this);
                    painter.setRenderHint(QPainter::Antialiasing);
                    painter.setBrush(brush);
                    painter.drawRoundedRect(0, 0, width(), height(), 100, 100);
                    QLabel::paintEvent(event);
                }
                

                But I can't scale it properly.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 27 Jan 2018, 14:23 last edited by
                  #25

                  Hi
                  well can scale the image to less that the size of the
                  QLabel so there are room to draw a circle around the image.
                  Since the image is the size of the Label , you cant draw outside the image.

                  so either make image smaller to it can be inside circle or
                  make image smaller so it fits in circle.

                  C 1 Reply Last reply 27 Jan 2018, 14:42
                  1
                  • M mrjj
                    27 Jan 2018, 14:23

                    Hi
                    well can scale the image to less that the size of the
                    QLabel so there are room to draw a circle around the image.
                    Since the image is the size of the Label , you cant draw outside the image.

                    so either make image smaller to it can be inside circle or
                    make image smaller so it fits in circle.

                    C Offline
                    C Offline
                    Cobra91151
                    wrote on 27 Jan 2018, 14:42 last edited by Cobra91151
                    #26

                    @mrjj

                    So now it looks much better:

                    0_1517064100797_2018-01-27_164133.png

                    void AccountImage::paintEvent(QPaintEvent *event)
                    {
                        QPixmap pixmap(":/Icon/default_avatar.png");
                        QPixmap scaled = pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                        QBrush brush(scaled);
                        QPainter painter(this);
                        painter.setRenderHint(QPainter::Antialiasing);
                        painter.setBrush(brush);
                        painter.drawRoundedRect(0, 0, width(), height(), 100, 100);
                        QLabel::paintEvent(event);
                    }
                    
                    M 1 Reply Last reply 27 Jan 2018, 14:45
                    0
                    • C Cobra91151
                      27 Jan 2018, 14:42

                      @mrjj

                      So now it looks much better:

                      0_1517064100797_2018-01-27_164133.png

                      void AccountImage::paintEvent(QPaintEvent *event)
                      {
                          QPixmap pixmap(":/Icon/default_avatar.png");
                          QPixmap scaled = pixmap.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                          QBrush brush(scaled);
                          QPainter painter(this);
                          painter.setRenderHint(QPainter::Antialiasing);
                          painter.setBrush(brush);
                          painter.drawRoundedRect(0, 0, width(), height(), 100, 100);
                          QLabel::paintEvent(event);
                      }
                      
                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 27 Jan 2018, 14:45 last edited by
                      #27

                      @Cobra91151
                      Ah yes. Like brush.
                      So you want image to be inside the circle and let it clip anything else.
                      I thought you wanted to paint a circle on it. :)

                      C 1 Reply Last reply 27 Jan 2018, 15:10
                      0
                      • M mrjj
                        27 Jan 2018, 14:45

                        @Cobra91151
                        Ah yes. Like brush.
                        So you want image to be inside the circle and let it clip anything else.
                        I thought you wanted to paint a circle on it. :)

                        C Offline
                        C Offline
                        Cobra91151
                        wrote on 27 Jan 2018, 15:10 last edited by Cobra91151
                        #28

                        @mrjj

                        So finally I have set it properly and it works great!

                        void AccountImage::paintEvent(QPaintEvent *event)
                        {
                            QPixmap pixmap(":/Icon/my_avatar.png");
                            QPixmap scaled = pixmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
                            QBrush brush(scaled);
                            QPainter painter(this);
                            painter.setRenderHint(QPainter::Antialiasing);
                            painter.setBrush(brush);
                            painter.drawRoundedRect(0, 0, width(), height(), 100, 100);
                            QLabel::paintEvent(event);
                        }
                        

                        Result:

                        0_1517065826536_2018-01-27_171006.png

                        Thank you for the help.

                        1 Reply Last reply
                        1

                        27/28

                        27 Jan 2018, 14:45

                        • Login

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