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. Background for images with alpha channel
Forum Updated to NodeBB v4.3 + New Features

Background for images with alpha channel

Scheduled Pinned Locked Moved General and Desktop
28 Posts 5 Posters 17.1k 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.
  • G Offline
    G Offline
    giesbert
    wrote on last edited by
    #21

    If you go that way, I would suggest using the paintEvent, as you are creating a temporary image for each changed frame. Then you cans also derive the label (or from QWidget diretly) and implement thepaint event. Then connect the signal with update and it should work with less temporary objects / images.

    @
    {
    ...
    gifSize=(QPixmap(archivo->absoluteFilePath()).size());

    movie->start();
    connect(movie, SIGNAL(frameChanged(int)), pImageLabel, SLOT(update()));
    
    //imageLabel->setMovie(movie);
    imageLabel->resize(gifSize);
    ...
    

    }

    void CMyImageLabel::CMyImageLabel(QPixmap backSquare) :
    m_squareBackground(backSquare)
    {
    }

    void CMyImageLabel::paintEvent()
    {
    QPainter paint(this);
    paint.drawTiledPixmap(rect(), m_squareBackground);
    paint.drawImage(rect(), myMove.currentImage());
    }
    @

    Nokia Certified Qt Specialist.
    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

    1 Reply Last reply
    0
    • S Offline
      S Offline
      samkpo
      wrote on last edited by
      #22

      Volker, i want to set both image and color.

      Gerolf, thanks for the improved code, and now i have two questions: the slot update() is from QWidget? (remember i said i was learning) and, can you explain better what is CMyImageLabel?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #23

        samkpo, ok if I understand you right you have

        • background color (e.g. red) on your lebel
        • a semi-background image with transparency on top of the background color
        • a movie with transparency on top of the semi-background image

        Am I right?

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #24

          update is a "slot of QWidget":http://doc.trolltech.com/4.7/qwidget.html#update, right.

          CMyImageLabel is a custom class, derived from QLabel or QWidget. If you need no functionality from QLabel (as you draw your image on your own) you can derive it from QWidget. Make the movie and the background image a member of the class. then connect the update slot and draw in the paintEvent.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            samkpo
            wrote on last edited by
            #25

            Volker, not exactly, i want to have:

            • background color on my label
            • a movie with transparency on top of the label

            or

            • an image on top of my label
            • a movie with transparency on top of the image

            i mean, it's not the color and the image together as backgrounds, it's the color or the image

            Gerolf, ok, i think i understand

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #26

              samkpo, I made up my mind. You will have to make your own widget, as Gerolf supposed. Basically you have to reimplement the paintEvent:

              movielabel.h

              @
              #ifndef MOVIELABEL_H
              #define MOVIELABEL_H

              #include <QWidget>
              #include <QPixmap>
              #include <QMovie>

              class MovieLabel : public QWidget
              {
              Q_OBJECT
              public:
              explicit MovieLabel(QWidget *parent = 0);

              signals:

              public slots:
              void start();
              void setMovie(const QString &file);
              void setBGPixmap(const QString &file);
              void setBGColor(QColor c);

              void drawFrame(int frameNumber);
              

              protected:
              void paintEvent(QPaintEvent *e);

              QMovie movie;
              QPixmap bgPixmap;
              QPixmap currentFrame;
              

              };

              #endif // MOVIELABEL_H
              @

              movielabel.cpp
              @
              #include "movielabel.h"

              #include <QPainter>
              #include <QPaintEvent>
              #include <QDebug>

              MovieLabel::MovieLabel(QWidget *parent) :
              QWidget(parent)
              {
              setAutoFillBackground(true);
              connect(&movie, SIGNAL(frameChanged(int)), this, SLOT(drawFrame(int)));
              }

              void MovieLabel::start()
              {
              movie.start();
              }

              void MovieLabel::setMovie(const QString &file)
              {
              movie.setFileName(file);
              }

              void MovieLabel::setBGPixmap(const QString &file)
              {
              bgPixmap.load(file);
              }

              void MovieLabel::setBGColor(QColor c)
              {
              QPalette p = palette();
              p.setColor(QPalette::Window, c);
              setPalette(c);
              }

              void MovieLabel::paintEvent(QPaintEvent *e)
              {
              if(bgPixmap.isNull())
              QWidget::paintEvent(e);

              QPainter p(this);
              if(!bgPixmap.isNull())
                  p.drawPixmap(e->rect(), bgPixmap, e->rect());
              
              p.drawPixmap(e->rect(), currentFrame, e->rect());
              

              }

              void MovieLabel::drawFrame(int frameNumber)
              {
              currentFrame = movie.currentPixmap();
              repaint();
              }
              @

              You will have to reimplement sizeHint and some more methods and insert some sanity checks for the movie and the pixmaps to make it a fully mature widget.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • S Offline
                S Offline
                samkpo
                wrote on last edited by
                #27

                ok guys, thanks a lot, i'll let you know when i finish it.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #28

                  [quote author="samkpo" date="1292799006"]ok guys, thanks a lot, i'll let you know when i finish it.[/quote]

                  Good luck!

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  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