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. qImage not showing inside custom promoted widget
Qt 6.11 is out! See what's new in the release blog

qImage not showing inside custom promoted widget

Scheduled Pinned Locked Moved General and Desktop
qimage qtdesign
5 Posts 2 Posters 2.0k Views 2 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi, I am trying to recreate the Qt Scribble example. I got it working by creating everything manually, now I am trying to use Qt Designer.

    I need a custom class that subclasses QWidget so that I can reimplement the paint and mouse click events for scribbling.
    I wrote the class and headers (paintarea.h, and paintarea.cpp). And then promoted a QWidget in QTDesigner into this class.

    Code is:
    paintarea.h

    #ifndef PAINTAREA_H
    #define PAINTAREA_H

    #include <QWidget>
    #include <QtWidgets>

    class PaintArea : public QWidget
    {
    Q_OBJECT
    public:
    explicit PaintArea(QWidget *parent = 0);

    private:
    QImage image;

    signals:

    public slots:
    };
    #endif // PAINTAREA_H

    paintarea.cpp

    PaintArea::PaintArea(QWidget *parent) : QWidget(parent)
    {
    image = QImage (500, 500, QImage::Format_ARGB32_Premultiplied);
    image.fill(qRgb(200,0,0));
    }

    Nothing displays inside the widget. I have tried for example a qSlider, and it shows up. But qImage won't work for some reason. I have tried isNull() to determine if the image is null, but it is not. It's just invisible.

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

      Hi and welcome to devnet,

      QImage is not a QWidget, if you want to see what it contains, you need to either use a QLabel to show it or paint it in a widget.

      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
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @SGaist But why does the QImage show if I code everything manually without using a promoted class in QTDesigner? Then the code above works.

        I'd like to use QTDesigner because it makes the UI work a lot faster but it seems to add a lot of headache as well.

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

          The exact same code shows a red image ?

          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
          • SGaistS SGaist

            The exact same code shows a red image ?

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @SGaist Yes, it's actually supposed to be a white background that you can paint on (like in the Qt Scribble example). And it works if I add all the elements manually, but in another project that uses QtDesigner with a QWidget promoted to PaintArea class, the QImage no longer shows up.

            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