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. Widget crops while rotating about its center
Forum Updated to NodeBB v4.3 + New Features

Widget crops while rotating about its center

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 248 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.
  • N Offline
    N Offline
    ndiwan
    wrote on last edited by ndiwan
    #1

    Hi All,
    I am facing a problem where I am trying to rotate a square about its center but as I keep on increasing oreintation, square getting cropped. Below is my code for reference:

    paintEvent(QPaintEvent * )
    {
    QPainter painter(this);
    //this->resize(m_nRectWidth+230 ,m_nRectHeight+30);
    QPen pen;

    pen = QPen(m_qcGateColor,1);
    painter.setPen(pen);
    QPainterPath m_RectPath = QPainterPath();
    QPainterPath m_SelectedPath = QPainterPath();
    m_RectPath.addRect(0,0,getRectWidth(),getRectHeight());
    m_SelectedPath.addRect(0,0, getRectWidth()-1, getRectHeight()-1);
    painter.translate(getRectWidth()/2, getRectHeight()/2);
    painter.rotate(m_Orientation);
    painter.translate(-getRectWidth()/2, -getRectHeight()/2);
    painter.setBrush(QBrush(m_qcGateColor));
    painter.drawPath(m_RectPath);
    
    if(IsSelected())
    {
        painter.setBrush(Qt::transparent);
        painter.setPen(QPen(Qt::green,3));
        painter.drawPath(m_SelectedPath);
    }
    pen = QPen(Qt::black,1);
    painter.setPen(pen);
    
    QRect rect = m_SelectedPath.boundingRect().toRect();
    QRegion Mask(rect);
    setMask(Mask);
    

    }
    Please suggest.

    Thanks
    Nitin

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

      Hi,

      What version of Qt ?
      On what platform ?
      What is the size of your widget ?
      What does getRectWidth return ?
      What does getRectHeight return ?
      Can you provide the complete code of your 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
      • N Offline
        N Offline
        ndiwan
        wrote on last edited by
        #3

        HI SGaist,
        Thanks for the response.
        Qt version: 4.8.2
        Platform Windows 10
        default size 30*30 ( Its a small square)
        getRectWidth returns width of the square
        getRectHeight returns height of the square
        Image added for your reference.

        Please let me know if you need anything else.

        Without orientation.PNG with_Orientation.PNG

        Thanks
        Nitin

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

          The complete widget code would be nice to recreate the situation locally.

          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
          1

          • Login

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