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. Rendering QWidget with children overriding paintEvent

Rendering QWidget with children overriding paintEvent

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 984 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.
  • J Offline
    J Offline
    Josselin
    wrote on last edited by
    #1

    Hello,

    I want to render a widget to save it in clipboard.
    Widget has children and one of them override paintEvent, setting transformations on a custom QPainter.

    void ImagesUtils::enregisterDansClipboard(QWidget* parent, QWidget* widgetACapturer)
    {
    	QPixmap pixmap(widgetACapturer->size());
    	widgetACapturer->render(&pixmap, QPoint(), QRegion(0, 0, widgetACapturer->size().width(), widgetACapturer->size().height()));
    	QApplication::clipboard()->setImage(pixmap.toImage());
    }
    
    
    void WidgetAxe::paintEvent(QPaintEvent *event)
    {
    	QPainter* painter = new QPainter(this);
    
    	painter->translate(rect().topRight());
    	painter->rotate(-90);
    	painter->scale(-1.0, 1.0);
    
    	...
    }
    

    This widget is drawn (and other children too), but the transformations are ignored. I guess it's is due to the fact that i use a custom QPainter, but I don't know how to resolve it.

    Thanks for your help.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Can you provide a minimal compilable example that shows that issue ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by Christian Ehrlicher
        #3

        @Josselin said in Rendering QWidget with children overriding paintEvent:

        QPainter* painter = new QPainter(this);

        Do you also delete this painter again? Why do you create it on the heap at all?
        And when you don't delete it you likely forgot to call QPainter:end()

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        J 1 Reply Last reply
        2
        • Christian EhrlicherC Christian Ehrlicher

          @Josselin said in Rendering QWidget with children overriding paintEvent:

          QPainter* painter = new QPainter(this);

          Do you also delete this painter again? Why do you create it on the heap at all?
          And when you don't delete it you likely forgot to call QPainter:end()

          J Offline
          J Offline
          Josselin
          wrote on last edited by
          #4

          @Christian-Ehrlicher said in Rendering QWidget with children overriding paintEvent:

          @Josselin said in Rendering QWidget with children overriding paintEvent:

          QPainter* painter = new QPainter(this);

          Do you also delete this painter again? Why do you create it on the heap at all?
          And when you don't delete it you likely forgot to call QPainter:end()

          Exactly. I forgot to delete my painter. Thanks for your reply, it works perfectly.
          The use of pointer is probably a bad habit (I'm a java developer, and i'm converting python code ), when I have to pass my object to a method

          Thanks for your help.

          jsulmJ 1 Reply Last reply
          0
          • J Josselin

            @Christian-Ehrlicher said in Rendering QWidget with children overriding paintEvent:

            @Josselin said in Rendering QWidget with children overriding paintEvent:

            QPainter* painter = new QPainter(this);

            Do you also delete this painter again? Why do you create it on the heap at all?
            And when you don't delete it you likely forgot to call QPainter:end()

            Exactly. I forgot to delete my painter. Thanks for your reply, it works perfectly.
            The use of pointer is probably a bad habit (I'm a java developer, and i'm converting python code ), when I have to pass my object to a method

            Thanks for your help.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Josselin said in Rendering QWidget with children overriding paintEvent:

            when I have to pass my object to a method

            You can pass a pointer to a stack allocated object

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            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