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. How parent object affect painting to child object?
Forum Updated to NodeBB v4.3 + New Features

How parent object affect painting to child object?

Scheduled Pinned Locked Moved General and Desktop
24 Posts 4 Posters 12.6k 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #7

    [quote author="Andre" date="1325071995"]Why do you use an eventfilter for painting? That seems wrong.[/quote]

    Actually i am making a general class inheriting from qobject. Inside that i have child window which i am painting. Can you please say me what is wrong in doing that?

    Pratik Agrawal

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #8

      Much. Widgets are supposed to paint themselves. You return true from your filter, which means that the widget cannot take responsibility for painting its contents or its borders or its children.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pratik041
        wrote on last edited by
        #9

        [quote author="Andre" date="1325072688"]Much. Widgets are supposed to paint themselves. You return true from your filter, which means that the widget cannot take responsibility for painting its contents or its borders or its children. [/quote]

        so how can i solve this problem?

        Pratik Agrawal

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #10

          Just use the system as it was designed to be used: by letting each widget paint itself.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pratik041
            wrote on last edited by
            #11

            [quote author="Andre" date="1325073247"]Just use the system as it was designed to be used: by letting each widget paint itself. [/quote]
            ok

            Pratik Agrawal

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pratik041
              wrote on last edited by
              #12

              [quote author="Andre" date="1325073247"]Just use the system as it was designed to be used: by letting each widget paint itself. [/quote]

              I have tried as you told but i am getting the same problem but the problem is coming in mac only not in windows.But one thing i noticed that when we press tab key the paint event is called infinite number of times.

              Pratik Agrawal

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #13

                Sorry, my crystal ball is broken, so I cannot see your code without you posting it.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pratik041
                  wrote on last edited by
                  #14

                  [quote author="Andre" date="1325147762"]Sorry, my crystal ball is broken, so I cannot see your code without you posting it.[/quote]
                  this is the code for paint event which i have used
                  @void ofi_vc_gui_panel::paintEvent (QPaintEvent *event)
                  {
                  QPainter paint(this); // Create a paint object.

                  // Store the source rect of the image.
                  QRect source = QRect(0, 0, dlg_data.cx, dlg_data.cy);
                  
                  // Store the target rect where image is to be drawn.
                  QRect target = QRect(0, 0, dlg_data.cx, dlg_data.cy);
                  
                  // Draw the image.
                  paint.drawPixmap (target, pixmap, source);
                  
                  i++;
                  qDebug ()<<"event"<<i;
                  

                  }
                  @

                  Pratik Agrawal

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #15

                    How about you start out with a call to <code>QWidget::paintEvent(event);</code> between your lines 2 and 3? Replace the QWidget with whatever is the base class of your widget. That way, the base class also gets a chance to do painting.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      pratik041
                      wrote on last edited by
                      #16

                      [quote author="Andre" date="1325150742"]How about you start out with a call to <code>QWidget::paintEvent(event);</code> between your lines 2 and 3? Replace the QWidget with whatever is the base class of your widget. That way, the base class also gets a chance to do painting. [/quote]

                      I have tried this also but same problem persists. Do you have mac system? If you have i will post you the sample code so that you can check.

                      Pratik Agrawal

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #17

                        No, I do not have a mac.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          pratik041
                          wrote on last edited by
                          #18

                          [quote author="Andre" date="1325158806"]No, I do not have a mac.[/quote]

                          now the problem is little bit solved. I was using Qmainwindow as a child of other QMainwindow. So the problem was coming. Now i have replaced child window with Qmdisubwindow so the painting problem is now solved. Does it is necessary to keep Qmdisubwindow in Qmdiarea or we can use it independently?Now only one problem is there the focus rect which i have drawn for button is not appearing in mac. I am using Qstyleoption for that does i have to write different style for mac or there would be some other problem? This is the code which i am using for drawing rect
                          @
                          QStyleOptionFocusRect option;
                          if (this->hasFocus ()) {

                              // Draw the focus frame for the widget having focus.
                              this->style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
                          }@
                          

                          Pratik Agrawal

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #19

                            Is there a reason you are not using QWidget instead of QMainWindow or QMdiSubWindow if you are using it as a widget anyway? These classes are not mend to be used as normal widgets.

                            I know nothing of the styles on mac, so I cannot guide you there.

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

                              An MDI subwindow is meant to be used in an MDI area. There's no gain to use it outside. And a main window as child of something else is pure nonsense. As is every window - those are toplevel by design.

                              Why do you paint yourself at all? What is wrong with the default provided widgets?

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

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                pratik041
                                wrote on last edited by
                                #21

                                [quote author="Andre" date="1325162997"]Is there a reason you are not using QWidget instead of QMainWindow or QMdiSubWindow if you are using it as a widget anyway? These classes are not mend to be used as normal widgets.

                                I know nothing of the styles on mac, so I cannot guide you there. [/quote]

                                I want to make generic window which may appear inside another window or as pop up window according to provided option. I was not using QWidget because in case of pop up window i want dockable property which i can found only on QMainwindow

                                Pratik Agrawal

                                1 Reply Last reply
                                0
                                • P Offline
                                  P Offline
                                  pratik041
                                  wrote on last edited by
                                  #22

                                  [quote author="Volker" date="1325183040"]An MDI subwindow is meant to be used in an MDI area. There's no gain to use it outside. And a main window as child of something else is pure nonsense. As is every window - those are toplevel by design.

                                  Why do you paint yourself at all? What is wrong with the default provided widgets?[/quote]
                                  I have painted myself because this is the requirement provided to me.

                                  Pratik Agrawal

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

                                    [quote author="pratik041" date="1325220949"]
                                    [quote author="Volker" date="1325183040"]
                                    Why do you paint yourself at all? What is wrong with the default provided widgets?[/quote]
                                    I have painted myself because this is the requirement provided to me.
                                    [/quote]

                                    And did you try to achieve your goal using standard widgets without painting yourself?

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

                                    1 Reply Last reply
                                    0
                                    • P Offline
                                      P Offline
                                      pratik041
                                      wrote on last edited by
                                      #24

                                      [quote author="Volker" date="1325243008"]
                                      [quote author="pratik041" date="1325220949"]
                                      [quote author="Volker" date="1325183040"]
                                      Why do you paint yourself at all? What is wrong with the default provided widgets?[/quote]
                                      I have painted myself because this is the requirement provided to me.
                                      [/quote]

                                      And did you try to achieve your goal using standard widgets without painting yourself?[/quote]

                                      I am now getting proper output with both painting and without it also.

                                      Pratik Agrawal

                                      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