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. SetWindowModified with QGraphicsView, is it bug?
Forum Updated to NodeBB v4.3 + New Features

SetWindowModified with QGraphicsView, is it bug?

Scheduled Pinned Locked Moved General and Desktop
15 Posts 2 Posters 6.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.
  • Z Offline
    Z Offline
    ZapB
    wrote on last edited by
    #4

    Indeed. I can reproduce this problem. As you say from the docs it looks as if this event should propagate up to the top-level parent window. I have stepped into the Qt code and this should be handled by the virtual QWidget::changeEvent() function but it isn't. I also tried it with a QTextEdit child widget instead of a QGraphicsView and got the same results. I'll dig a little deeper.

    Nokia Certified Qt Specialist
    Interested in hearing about Qt related work

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #5

      Hmmm this looks to be a bug. As a work around you could emit your own sceneModified() signal form within your mousePressEvent() function and connect this up to a slot in your mainwindow that just does:

      @
      void MainWindow::onSceneModified()
      {
      setWindowModified( true );
      }
      @

      This is what the Qt examples do.

      I have even tried overriding changeEvent() in a mainwindow but it does not receive the supposedly propagated ModifiedChange event.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #6

        I have confirmed on IRC that this is indeed a bug in Qt. I'll file a bug report and let you know where it is. In the interim just use the above work around.

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #7

          I have filed a bug in JIRA. You can find it at http://bugreports.qt.nokia.com/browse/QTBUG-20150

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maherali
            wrote on last edited by
            #8

            Thank you ZapB, it's really weird I'm working with qt for 1 month, it's too early to find such a bug.

            Regards

            life is just lines of code

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on last edited by
              #9

              I think it is a regression (judging by comments on other related bug reports). If I get the time I'll see about making a patch to fix it.

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maherali
                wrote on last edited by
                #10

                I'll try to emit the events manually, I need sometime to read about Events mechanisms in Qt and let you know, thanks

                life is just lines of code

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  ZapB
                  wrote on last edited by
                  #11

                  Something like this should do it:

                  In your YPeersView headr file add a new sceneModified() signal:

                  @
                  class YPeersView : public QGraphicsView {
                  Q_OBJECT
                  public:
                  ...

                  signals:
                  void sceneModified();

                  ...
                  

                  };
                  @

                  Be sure to emit this in you handler instead of calling setWindowModified:
                  @
                  YPeerNode* YPeersView::addNode(QPointF pos)
                  {
                  YPeerNode* node=new YPeerNode(5);
                  node->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);

                  if(scene())
                  {
                      scene()->addItem(node);
                      scene()->clearSelection();
                      
                      /** \bug In Qt - work around using custom signal */
                      //setWindowModified(true);
                      emit sceneModified();
                  
                      node->update();       
                      itemsCountChanged(scene()->items().count());
                      return node;
                  }
                  return 0;
                  

                  }
                  @

                  In your mainwindow header add a new slot to handle this signal:

                  @
                  class MainWindow : public QMainWindow {
                  Q_OBJECT
                  public:
                  ...

                  public slots:
                  void onSceneModified() { setWindowModified( true ); }
                  };
                  @

                  And finally make the connection in your mainwindow ctor (or somewhere else convenient):

                  @
                  MainWindow::MainWindow( QWidget* parent )
                  : QMainWindow( parent )
                  {
                  ...
                  connect( m_view, SIGNAL( sceneModified() ), this, SLOT( onSceneModified() ) );
                  }
                  @

                  That should do it I think.

                  Nokia Certified Qt Specialist
                  Interested in hearing about Qt related work

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    maherali
                    wrote on last edited by
                    #12

                    Thanks ZapB
                    I'm already using Signals/Slots to notify the parent that the scene items number has been changed
                    but I was working on implementing events handlers (custom events)
                    I've read that signals/slots don't use separate threads which means non-responsive program.

                    I'll try to call events, if it didn't work I'll use the signal/slot mechanism.

                    life is just lines of code

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      maherali
                      wrote on last edited by
                      #13

                      Hi
                      I did it using the events
                      My custom event
                      @
                      class YChangedEvent : public QEvent
                      {
                      public:
                      YChangedEvent();
                      };
                      @

                      in the view custom class I use this function
                      @
                      void YPeersView::sceneStateChanged()
                      {
                      QApplication::postEvent(parent(),new YChangedEvent());
                      }
                      @

                      in the Mainwindow
                      @
                      void YPeerScenarioWidget::customEvent(QEvent *e)
                      {

                      if(e->type()==YEvents::YCHANGEDEVENT)
                      {
                          setWindowModified(true);
                      }
                      

                      }

                      @

                      it works, thanks ZapB
                      I think I started to love Qt more than C#

                      life is just lines of code

                      1 Reply Last reply
                      0
                      • Z Offline
                        Z Offline
                        ZapB
                        wrote on last edited by
                        #14

                        Yeah either approach will work. Signals/slots work just like direct function calls if both objects have affinity with the same thread (which yours do form the loosk of things). If the sender and receiver are affine with different threads then the signal/slot mechanism actually uses QEvents behined the scenes and the slot works asynchronously.

                        Of course if you are comfortable using custom events yourself then either approach works perfectly fine.

                        Glad you got it working anyway. Have fun with the rest of your project.

                        Nokia Certified Qt Specialist
                        Interested in hearing about Qt related work

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          maherali
                          wrote on last edited by
                          #15

                          Oh that's good point, Slots/Signals mechanism is really flexible.
                          It will save us lot of time.

                          Thanks for your help

                          life is just lines of code

                          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