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. Custom Widget creation to display in QGridLayout cell.

Custom Widget creation to display in QGridLayout cell.

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 243 Views
  • 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I am creating a new class based on QWidget, its very early stages. So far the paintEvent function contains just:

    void truth::paintEvent(QPaintEvent* pEvent) {
        QRect rctGeom(geometry());
        QColor colBG(mobjBGcol.toString());
    
        bool blnValidgeom(rctGeom.isValid());
        bool blnValidColor(colBG.isValid());
    qDebug() << rctGeom.x() << ", " << rctGeom.y() << ", " << rctGeom.width() << ", " << rctGeom.height();
    
        QPainter objVisible(this);
        objVisible.fillRect(rctGeom, colBG);
    }
    

    mobjBGcol is an instance of QJsonValue which contains #ffff0077.

    With the above code I see nothing, if I insert:

    rctGeom.setX(0);
    rctGeom.setY(0);
    this->setGeometry(rctGeom);
    

    Above the qDebug() line, I see a magenta filled rectangle but not in the correct location. The widget I'm creating is added to a QGridLayout with:

    mpui->pgrdloContent->addWidget(pGroundTruth, 2, 2);
    

    What I really want to is get the widget to fill the cell in the grid layout, with the setGeometry it doesn't and the rectangle appears on the top left of the rectangle not in the layout at all. Without the geometry setting, nothing is appearing at all.

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      I am creating a new class based on QWidget, its very early stages. So far the paintEvent function contains just:

      void truth::paintEvent(QPaintEvent* pEvent) {
          QRect rctGeom(geometry());
          QColor colBG(mobjBGcol.toString());
      
          bool blnValidgeom(rctGeom.isValid());
          bool blnValidColor(colBG.isValid());
      qDebug() << rctGeom.x() << ", " << rctGeom.y() << ", " << rctGeom.width() << ", " << rctGeom.height();
      
          QPainter objVisible(this);
          objVisible.fillRect(rctGeom, colBG);
      }
      

      mobjBGcol is an instance of QJsonValue which contains #ffff0077.

      With the above code I see nothing, if I insert:

      rctGeom.setX(0);
      rctGeom.setY(0);
      this->setGeometry(rctGeom);
      

      Above the qDebug() line, I see a magenta filled rectangle but not in the correct location. The widget I'm creating is added to a QGridLayout with:

      mpui->pgrdloContent->addWidget(pGroundTruth, 2, 2);
      

      What I really want to is get the widget to fill the cell in the grid layout, with the setGeometry it doesn't and the rectangle appears on the top left of the rectangle not in the layout at all. Without the geometry setting, nothing is appearing at all.

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

      @SPlatten said in Custom Widget creation to display in QGridLayout cell.:

      What I really want to is get the widget to fill the cell in the grid layout

      The widget can only paint on its own surface.
      https://doc.qt.io/qt-5/qwidget.html#geometry-prop: "This property holds the geometry of the widget relative to its parent and excluding the window frame". What you need is https://doc.qt.io/qt-5/qwidget.html#rect-prop

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

      SPlattenS 1 Reply Last reply
      2
      • jsulmJ jsulm

        @SPlatten said in Custom Widget creation to display in QGridLayout cell.:

        What I really want to is get the widget to fill the cell in the grid layout

        The widget can only paint on its own surface.
        https://doc.qt.io/qt-5/qwidget.html#geometry-prop: "This property holds the geometry of the widget relative to its parent and excluding the window frame". What you need is https://doc.qt.io/qt-5/qwidget.html#rect-prop

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        @jsulm , excellent thank you!

        Kind Regards,
        Sy

        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