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. QFlipWidget -- what did I break?

QFlipWidget -- what did I break?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 793 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 Offline
    M Offline
    marshaul
    wrote on last edited by
    #1

    I need a way to flip an image to reveal another image on its back -- like flipping a playing card -- for a Qt application I'm writing.

    I found some example code under the name QFlipWidget (source available here), which provides exactly the effect I want.

    However, I don't need or want all the several layers of nested widgets and layouts and whatnot, so I decided to modify the code by stripping it down to just what I need - removing layouts, QGraphicsProxyWidgets, the RoundedRect class entirely, etc. Since I'm looking for just a pair of images (from jpg files or whatever), I figured I didn't need anything more than a couple of QGraphicsPixmapItems to put in the QGraphicsScene and it should work the same.

    After making these changes, my images were side-by-side and the axis of rotation was the line of intersection between the two images, instead of "stacked" on top of each other as they appear to be in QFlipWidget. No problem, I thought, so I set the images' offset so they occupy the same space, but now I have the problem that the front image stays on top always -- after being flipped I merely see the front imaged reverse. During the animation I can see a portion of the back image so I know it's there, just not being rendered over the front image.

    I assume that some part of the old code caused the visibility flag to become false around the halfway point of the animation, but for the life of me I can't figure out where that is in the code (or in inherited classes) or if that's even the correct mechanism.

    So, I have two questions:

    In the original QFlipWidget, how is the visibility of the item which is on the not-presently-displayed side handled? That is, what causes the back image to come around on the second half of the rotation transform, instead of just flipping the front image around?

    How can I achieve this effect absent whatever mechanism I stripped in the process of removing the extraneous stuff?

    As far as I can see, this is the only substantive/relevant portion of changed code (it's from the constructor of the FlipWidget class):

    //--Front Widget
    QString frontPath = "/path/to/image1.jpg";
    m_frontPixmap = new QPixmap(frontPath);
    m_frontItem = new QGraphicsPixmapItem(QPixmap(frontPath));

    //Create the scene and add the items
    m_scene = new QGraphicsScene(-300,0,600,600, this);
    this->setScene(m_scene);
    m_scene->addItem(m_frontItem);

    //--BackWidget
    QString backPath = "/path/to/image2.jpg";
    m_backPixmap = new QPixmap(backPath);
    m_backItem = new QGraphicsPixmapItem(QPixmap(backPath));
    m_backItem->setTransform(QTransform().rotate(180, Qt::YAxis));
    m_backItem->setParentItem(m_frontItem);
    m_backItem->setOffset(-300,0);

    //--Widget size
    this->setMaximumWidth(598);

    CKurduC 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Difficult to answer this question as this issue is not directly related to Qf. If somebody has used the flip widget will help. Otherwise you may check with author QFlipWidget itself.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • M marshaul

        I need a way to flip an image to reveal another image on its back -- like flipping a playing card -- for a Qt application I'm writing.

        I found some example code under the name QFlipWidget (source available here), which provides exactly the effect I want.

        However, I don't need or want all the several layers of nested widgets and layouts and whatnot, so I decided to modify the code by stripping it down to just what I need - removing layouts, QGraphicsProxyWidgets, the RoundedRect class entirely, etc. Since I'm looking for just a pair of images (from jpg files or whatever), I figured I didn't need anything more than a couple of QGraphicsPixmapItems to put in the QGraphicsScene and it should work the same.

        After making these changes, my images were side-by-side and the axis of rotation was the line of intersection between the two images, instead of "stacked" on top of each other as they appear to be in QFlipWidget. No problem, I thought, so I set the images' offset so they occupy the same space, but now I have the problem that the front image stays on top always -- after being flipped I merely see the front imaged reverse. During the animation I can see a portion of the back image so I know it's there, just not being rendered over the front image.

        I assume that some part of the old code caused the visibility flag to become false around the halfway point of the animation, but for the life of me I can't figure out where that is in the code (or in inherited classes) or if that's even the correct mechanism.

        So, I have two questions:

        In the original QFlipWidget, how is the visibility of the item which is on the not-presently-displayed side handled? That is, what causes the back image to come around on the second half of the rotation transform, instead of just flipping the front image around?

        How can I achieve this effect absent whatever mechanism I stripped in the process of removing the extraneous stuff?

        As far as I can see, this is the only substantive/relevant portion of changed code (it's from the constructor of the FlipWidget class):

        //--Front Widget
        QString frontPath = "/path/to/image1.jpg";
        m_frontPixmap = new QPixmap(frontPath);
        m_frontItem = new QGraphicsPixmapItem(QPixmap(frontPath));

        //Create the scene and add the items
        m_scene = new QGraphicsScene(-300,0,600,600, this);
        this->setScene(m_scene);
        m_scene->addItem(m_frontItem);

        //--BackWidget
        QString backPath = "/path/to/image2.jpg";
        m_backPixmap = new QPixmap(backPath);
        m_backItem = new QGraphicsPixmapItem(QPixmap(backPath));
        m_backItem->setTransform(QTransform().rotate(180, Qt::YAxis));
        m_backItem->setParentItem(m_frontItem);
        m_backItem->setOffset(-300,0);

        //--Widget size
        this->setMaximumWidth(598);

        CKurduC Offline
        CKurduC Offline
        CKurdu
        wrote on last edited by CKurdu
        #3

        Hi,
        @marshaul said in QFlipWidget -- what did I break?:

        I assume that some part of the old code caused the visibility flag to become false around the halfway point of the animation

        In "RoundRectItem.cpp" file at line 38, there is a logic that hides the backward widget.

            if( m_proxyWidget && m_proxyWidget->isVisible() ) 
                {
                    m_proxyWidget->hide();
                    m_proxyWidget->setGeometry( rect() );
                }
                return;
        

        So I think you may create a class that is similar to RoundRectItem but only for checking and setting the visibility and geometry.

        You reap what you sow it

        M 1 Reply Last reply
        0
        • CKurduC CKurdu

          Hi,
          @marshaul said in QFlipWidget -- what did I break?:

          I assume that some part of the old code caused the visibility flag to become false around the halfway point of the animation

          In "RoundRectItem.cpp" file at line 38, there is a logic that hides the backward widget.

              if( m_proxyWidget && m_proxyWidget->isVisible() ) 
                  {
                      m_proxyWidget->hide();
                      m_proxyWidget->setGeometry( rect() );
                  }
                  return;
          

          So I think you may create a class that is similar to RoundRectItem but only for checking and setting the visibility and geometry.

          M Offline
          M Offline
          marshaul
          wrote on last edited by marshaul
          #4

          @CKurdu Oh, how did I miss that?

          Good catch, I guess I wasn't paying enough attention to RoundRectItem, which I should have because it was one of the things I wanted to strip.

          Thank you very much. I'd like to say that I posted this on stackexchange and had the question promptly closed by a bunch of CSS wranglers based on some non-sequitur justification. So thanks for actually helping! :)

          CKurduC 1 Reply Last reply
          0
          • M marshaul

            @CKurdu Oh, how did I miss that?

            Good catch, I guess I wasn't paying enough attention to RoundRectItem, which I should have because it was one of the things I wanted to strip.

            Thank you very much. I'd like to say that I posted this on stackexchange and had the question promptly closed by a bunch of CSS wranglers based on some non-sequitur justification. So thanks for actually helping! :)

            CKurduC Offline
            CKurduC Offline
            CKurdu
            wrote on last edited by
            #5

            @marshaul
            You are welcome. If the answer really solves the problem, you can mark as solved from the topic tools.

            You reap what you sow it

            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