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. Using a custom QGraphicsEffect
Forum Updated to NodeBB v4.3 + New Features

Using a custom QGraphicsEffect

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 904 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.
  • Chris HennesC Offline
    Chris HennesC Offline
    Chris Hennes
    wrote on last edited by
    #1

    I think I am misunderstanding something fundamental about QGraphicsEffect. Right now I'm actually trying to create an effect that does nothing: that literally just takes its input pixmap and draws it, unchanged. Based on my reading of the example code and the documentation, the simplest conceivable implementation of the draw() function is:

    void PreviousFrameOverlayEffect::draw(QPainter *painter)
    {
        const QPixmap pixmap = sourcePixmap();
        painter->drawPixmap(pixmap.rect(), pixmap);
    }
    

    I've got my code rigged up so that this effect is only applied while I'm holding down a key on the keyboard. It's being applied to a QCameraViewfinder. The viewfinder shows the correct camera view when the key is not pressed, but when it is pressed, the screen basically goes blank, with just some tiny triangles showing at the left and right edges of the drawing region. Releasing the key to disable the effect drops me back into normal output from the viewfinder. What is wrong with that code? How do I just regurgitate the input pixmap? Obviously that's only the first step in my code, but until I can get that working there's no point in writing the real effect!

    Chris Hennes, Pioneer Library System

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lachdanan
      wrote on last edited by
      #2

      @Chris-Hennes said in Using a custom QGraphicsEffect:

      sourcePixmap();
      painter->drawPixmap(pixmap.rect(), pixmap);

      I have the exact same problem when trying to create a graphics effect that does nothing.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adazem009
        wrote on last edited by
        #3

        Calling drawSource() from draw() will do the job.

        void PreviousFrameOverlayEffect::draw(QPainter *painter)
        {
            drawSource(painter);
        }
        

        Another way, which should do the same, but in my case I'm experiencing some rendering glitches with this one:

        void PreviousFrameOverlayEffect::draw(QPainter *painter)
        {
            QPoint offset;
            const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset);
            painter->drawPixmap(offset, pixmap);
        }
        
        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