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. Problem with widget
Qt 6.11 is out! See what's new in the release blog

Problem with widget

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

    I'm having a problem with a widget so in an effort to see what is going on I want to add an additional rectangle to the widget so I can render debug information to this new rectangle.

    In the paintEvent I get the geometry:

    QRect rctGeom(rect());
    #if defined(TRUTH_DEV)
    if ( mblnVisibleCopy == true && mrctDev.isEmpty == true ) {
    //Adjust widget geometry allowing for the development area
        int intWidth(rctGeom.width());
        rctGeom.adjust(0, 0,intWidthh, 0);
    qDebug() << "BEFORE: " << rctGeom;
        setGeometry(rctGeom);
    qDebug() << "AFTER: " << geometry();
        mrctDev = rctGeom;
        mrctDev.adjust(intWidth, + 40, intWidth, -40);
    qDebug() << "rctGeom: " << rctGeom << ", mrctDev: " << mrctDev;
    }
    #endif
    

    The output from above is:

    BEFORE: QRect(0,0 416x644)
    AFTER: QRect(0,0 208x644)
    rctGeom: QRect(0,0 416x644), mrctDev: QRect(208,40 416x564)
    

    I'm not sure why the geometry in the AFTER message has a narrow width after calling setGeometry.
    [Edit], I just tried:

    QRect rctGeom(rect());
    #if defined(TRUTH_DEV)
    if ( mblnVisibleCopy == true && mrctDev.isEmpty == true ) {
    //Adjust widget geometry allowing for the development area
        int intWidth(rctGeom.width());
    qDebug() << "BEFORE: " << rctGeom;
        resize(intWidth*2, rctGeom.height());
    qDebug() << "AFTER: " << geometry();
        mrctDev = rctGeom;
        mrctDev.adjust(intWidth, + 40, intWidth, -40);
    qDebug() << "rctGeom: " << rctGeom << ", mrctDev: " << mrctDev;
    }
    #endif
    

    Now the output is:

    BEFORE: QRect(0,0 208x644)
    AFTER: QRect(897,32 208x644)
    rctGeom: QRect(0,0 208x644), mrctDev: QRect(208,40 208x564)
    

    I'm very confused.

    Kind Regards,
    Sy

    J.HilkJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      I'm having a problem with a widget so in an effort to see what is going on I want to add an additional rectangle to the widget so I can render debug information to this new rectangle.

      In the paintEvent I get the geometry:

      QRect rctGeom(rect());
      #if defined(TRUTH_DEV)
      if ( mblnVisibleCopy == true && mrctDev.isEmpty == true ) {
      //Adjust widget geometry allowing for the development area
          int intWidth(rctGeom.width());
          rctGeom.adjust(0, 0,intWidthh, 0);
      qDebug() << "BEFORE: " << rctGeom;
          setGeometry(rctGeom);
      qDebug() << "AFTER: " << geometry();
          mrctDev = rctGeom;
          mrctDev.adjust(intWidth, + 40, intWidth, -40);
      qDebug() << "rctGeom: " << rctGeom << ", mrctDev: " << mrctDev;
      }
      #endif
      

      The output from above is:

      BEFORE: QRect(0,0 416x644)
      AFTER: QRect(0,0 208x644)
      rctGeom: QRect(0,0 416x644), mrctDev: QRect(208,40 416x564)
      

      I'm not sure why the geometry in the AFTER message has a narrow width after calling setGeometry.
      [Edit], I just tried:

      QRect rctGeom(rect());
      #if defined(TRUTH_DEV)
      if ( mblnVisibleCopy == true && mrctDev.isEmpty == true ) {
      //Adjust widget geometry allowing for the development area
          int intWidth(rctGeom.width());
      qDebug() << "BEFORE: " << rctGeom;
          resize(intWidth*2, rctGeom.height());
      qDebug() << "AFTER: " << geometry();
          mrctDev = rctGeom;
          mrctDev.adjust(intWidth, + 40, intWidth, -40);
      qDebug() << "rctGeom: " << rctGeom << ", mrctDev: " << mrctDev;
      }
      #endif
      

      Now the output is:

      BEFORE: QRect(0,0 208x644)
      AFTER: QRect(897,32 208x644)
      rctGeom: QRect(0,0 208x644), mrctDev: QRect(208,40 208x564)
      

      I'm very confused.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @SPlatten
      possibly:

      The size component is adjusted if it lies outside the range defined by minimumSize() and maximumSize().

      https://doc.qt.io/qt-5/qwidget.html#geometry-prop


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      SPlattenS 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

        @SPlatten
        possibly:

        The size component is adjusted if it lies outside the range defined by minimumSize() and maximumSize().

        https://doc.qt.io/qt-5/qwidget.html#geometry-prop

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

        @J-Hilk , thank you, modified to:

        QRect rctGeom(rect());
        #if defined(TRUTH_DEV)
        if ( mblnVisibleCopy == true && mrctDev.isEmpty == true ) {
        //Save current size
            Size szCurrent(size()), szNew;
        //Adjust maxmum size to prevent geometry being rejected
            szNew.setWidth(szCurrent.width() * 2);
            szNew.setHeight(szCurrent.height());
        //Adjust widget geometry allowing for the development area
            qDebug() << "BEFORE: " << rctGeom;
            resize(szNew);
            rctGeom = geometry();
            qDebug() << "AFTER: " << rctGeom;
            mrctDev = rctGeom;
            mrctDev.adjust(szCurrent.width(), + 40, szCurrent.width(), -40);
        qDebug() << "rctGeom: " << rctGeom << ", mrctDev: " << mrctDev;
        }
        #endif
        

        Results:

        BEFORE: QRect(0,0 208x644)
        AFTER: QRect(897,32 416x644)
        rctGeom: QRect(897,32 416x644), mrctDev: QRect(1105,72 416x564)
        

        Thank you!

        Kind Regards,
        Sy

        1 Reply Last reply
        1

        • Login

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