Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Attempting to change QImage text
Forum Updated to NodeBB v4.3 + New Features

Attempting to change QImage text

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 341 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.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by
    #1

    I have a QImage which I am painting in the constructor like so:

        QImage image(prjcfgISO11783UT_datamaskWidth+2, prjcfgISO11783UT_datamaskHeight+2, QImage::Format_Mono);
        image.fill(1);
        QPainter painter;
    
        painter.begin(&image);
    
        painter.setPen(Qt::black);
        painter.drawText(QRect(0, 0, prjcfgISO11783UT_datamaskWidth+2, prjcfgISO11783UT_datamaskHeight+2), Qt::AlignCenter, tr("Some Text..", "header with description"));
    
        m_image = image;
    

    and I have a translate() method setup like so:

      bool TheObject::event(QEvent *event)
      {
        if (event->type() == QEvent::LanguageChange)
        {
          retranslate();
        }
        return false;
      }
    
      void DataMaskObject::retranslate()
      {
        
      }
    

    how can I go about re-translating the text of m_image?

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

      Hi,

      Put the image setup code in its own method and call it from the constructor and retranslate.

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

      C 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Put the image setup code in its own method and call it from the constructor and retranslate.

        C Offline
        C Offline
        Circuits
        wrote on last edited by Circuits
        #3

        @SGaist Is there no way to change the text created by painter.drawText inline? The QImage setText() doesn't seem to work like I think it should:

        m_image.setText(tr("header"), tr("New String"));
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          No, you have to redraw it as setText is for metadata.

          What is the issue with the solution I suggested ?

          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
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved