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. Not redraw when the application is resized

Not redraw when the application is resized

Scheduled Pinned Locked Moved Solved General and Desktop
2d graphicsevent
7 Posts 3 Posters 1.1k 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.
  • timob256T Offline
    timob256T Offline
    timob256
    wrote on last edited by timob256
    #1

    does not redraw when the application is resized. :-(

    All code

    main.cpp

    #include "hotdog.h"
    
    #include <QApplication>
    #include <QScreen>
    #include <QDebug>
    
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        HotDog w;
        //выставляем подстройку к размеру экрана
        QSize screenSize = qApp->screens().at(0)->availableSize();
        const int width = screenSize.width() / 2.5;
        const int height = screenSize.height() * 0.5;
        w.setGeometry((screenSize.width() - width) / 2.0,
                      (screenSize.height() - height) / 2.0,
                      width,
                      height);
        w.setWindowTitle("Хот-дог");
        
        w.setScale((float)width, (float)height);
    
        w.show();
        return a.exec();
    }
    

    Hotdog.h

    #ifndef HOTDOG_H
    #define HOTDOG_H
    
    #include <QWidget>
    #include <QPainter>
    #include <QColor>
    #include <QDebug>
    #include <QtMath>
     #include <QKeyEvent>
    
    
    class HotDog : public QWidget {
        Q_OBJECT
    public:
        using QWidget::QWidget;
    
        // туту сетеры  гетеры
        ///
        /// \brief setColor выбор цвета
        ///
        void setColor(int r, int g, int b, int a);
    
        ///
        /// \brief setColor выбор цвета "основной" линии
        ///
        void setColorLine(int r, int g, int b, int a);
    
        ///
        /// \brief setScaleFactor установить коэффициент масштаба
        ///
        void setScale(float height, float width);
    
        ///
        /// \brief setPosition установить расположение обьекта
        ///
        void setPosition(float x, float y);
    
    private:
        // туту слоты
        
        //тут настройки для рисунков и сцены
        QColor   _color            {220, 220, 0, 227};
        QColor   _color_line    {0, 0, 0, 255}; //  ченый не прозрачный
        float    _razmer            {0};        // базовый размер (рамер рисука чтоб не потек) 
        float    _thickness       {0};        // толщина оучки
        float    _x                      {0};
        float    _y                      {0};
        float    _R                      {0};
        
        // тут данные "рисунlка"
        QList <QPointF> _my_point        {50};
        
        
        
    
    
    protected:
        virtual void moveEvent (QMoveEvent *event);           // вызов если окно двигается
        virtual void resizeEvent (QResizeEvent *event);       // вызов если рамер экрана меняется
        virtual void paintEvent(QPaintEvent *event);          // тут рисуем
    //    virtual QSize sizeHint() const;                                        // тут задаем размеры (возми из иного прмера)
        virtual void mousePressEvent(QMouseEvent * event);        // тут нажатие клавиши (зажатие)
        virtual void mouseReleaseEvent(QMouseEvent * event);      // тут зажатие клавиши (отддатие  )
        virtual void keyPressEvent(QKeyEvent *event);             // нажимаем клавиши получаем результат (увеличение и уменьшение чсла точек)
    };
    
    #endif // HOTDOG_H
    

    hotdog.cpp

    #include "hotdog.h"
    
    void HotDog::setColor(int r, int g, int b, int a)
    {
        _color.setRgb(r,g,b,a);
    }
    
    void HotDog::setColorLine(int r, int g, int b, int a)
    {
        _color_line.setRgb(r,g,b,a);
    }
    
    void HotDog::setScale(float height, float width)
    {
        // _height = height;
        //_width = width;
        // тут попробую высчитать базовый размер чтоб неболо растяжения картинки
        if(height > width) 
             _razmer = width;
        if(width > height) 
             _razmer = height;
             
        _thickness = _razmer/50.0;
        _R = _razmer/3.0;
    }
    
    void HotDog::setPosition(float x, float y)
    {
        _x = x;
        _y = y;
    }
    
    void HotDog::paintEvent(QPaintEvent *event)
    {
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing, true);
    
        painter.setPen(QPen(_color_line, _thickness, Qt::SolidLine));
        // painter.setBrush(QBrush(_color));
        painter.setBrush(QBrush(Qt::NoBrush));
        
        painter.drawRect(_x, _y, _razmer, _razmer); // рамка просто чтоб было
    
        qDebug() << "_my_point.size() " <<_my_point.size();
    
        qreal t=0;
        for(int i =0; _my_point.size() >= i; i++) 
           {
                 painter.drawPoint(_razmer/2+_R*qCos(t), _razmer/2+_R*qSin(t));
                 t+=(2 * M_PI)/_my_point.size();
                 qDebug() << "t" <<t;
           }
    }
    
    void HotDog::mousePressEvent(QMouseEvent *event)
    {
    
    }
    
    void HotDog::mouseReleaseEvent(QMouseEvent *event)
    {
    
    }
    
    void HotDog::moveEvent (QMoveEvent *event)
    {
    	qDebug() << "moveEvent " << "x " << event->pos().x()<< "y " << event->pos().y();
    }
    
    void HotDog::resizeEvent (QResizeEvent *event)
    {
    	qDebug() << "resizeEvent " << "width " << event->size().width()<< "height" << event->size().height();
        //HotDog::paintEvent(QPaintEvent *event);
        repaint();
    }
    
    void HotDog::keyPressEvent(QKeyEvent *event) 
    {
     
     }
    

    Снимок экрана от 2022-08-20 23-37-01.png

    Снимок экрана от 2022-08-20 23-36-59.png

    Christian EhrlicherC mrjjM timob256T 3 Replies Last reply
    0
    • timob256T timob256

      does not redraw when the application is resized. :-(

      All code

      main.cpp

      #include "hotdog.h"
      
      #include <QApplication>
      #include <QScreen>
      #include <QDebug>
      
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          HotDog w;
          //выставляем подстройку к размеру экрана
          QSize screenSize = qApp->screens().at(0)->availableSize();
          const int width = screenSize.width() / 2.5;
          const int height = screenSize.height() * 0.5;
          w.setGeometry((screenSize.width() - width) / 2.0,
                        (screenSize.height() - height) / 2.0,
                        width,
                        height);
          w.setWindowTitle("Хот-дог");
          
          w.setScale((float)width, (float)height);
      
          w.show();
          return a.exec();
      }
      

      Hotdog.h

      #ifndef HOTDOG_H
      #define HOTDOG_H
      
      #include <QWidget>
      #include <QPainter>
      #include <QColor>
      #include <QDebug>
      #include <QtMath>
       #include <QKeyEvent>
      
      
      class HotDog : public QWidget {
          Q_OBJECT
      public:
          using QWidget::QWidget;
      
          // туту сетеры  гетеры
          ///
          /// \brief setColor выбор цвета
          ///
          void setColor(int r, int g, int b, int a);
      
          ///
          /// \brief setColor выбор цвета "основной" линии
          ///
          void setColorLine(int r, int g, int b, int a);
      
          ///
          /// \brief setScaleFactor установить коэффициент масштаба
          ///
          void setScale(float height, float width);
      
          ///
          /// \brief setPosition установить расположение обьекта
          ///
          void setPosition(float x, float y);
      
      private:
          // туту слоты
          
          //тут настройки для рисунков и сцены
          QColor   _color            {220, 220, 0, 227};
          QColor   _color_line    {0, 0, 0, 255}; //  ченый не прозрачный
          float    _razmer            {0};        // базовый размер (рамер рисука чтоб не потек) 
          float    _thickness       {0};        // толщина оучки
          float    _x                      {0};
          float    _y                      {0};
          float    _R                      {0};
          
          // тут данные "рисунlка"
          QList <QPointF> _my_point        {50};
          
          
          
      
      
      protected:
          virtual void moveEvent (QMoveEvent *event);           // вызов если окно двигается
          virtual void resizeEvent (QResizeEvent *event);       // вызов если рамер экрана меняется
          virtual void paintEvent(QPaintEvent *event);          // тут рисуем
      //    virtual QSize sizeHint() const;                                        // тут задаем размеры (возми из иного прмера)
          virtual void mousePressEvent(QMouseEvent * event);        // тут нажатие клавиши (зажатие)
          virtual void mouseReleaseEvent(QMouseEvent * event);      // тут зажатие клавиши (отддатие  )
          virtual void keyPressEvent(QKeyEvent *event);             // нажимаем клавиши получаем результат (увеличение и уменьшение чсла точек)
      };
      
      #endif // HOTDOG_H
      

      hotdog.cpp

      #include "hotdog.h"
      
      void HotDog::setColor(int r, int g, int b, int a)
      {
          _color.setRgb(r,g,b,a);
      }
      
      void HotDog::setColorLine(int r, int g, int b, int a)
      {
          _color_line.setRgb(r,g,b,a);
      }
      
      void HotDog::setScale(float height, float width)
      {
          // _height = height;
          //_width = width;
          // тут попробую высчитать базовый размер чтоб неболо растяжения картинки
          if(height > width) 
               _razmer = width;
          if(width > height) 
               _razmer = height;
               
          _thickness = _razmer/50.0;
          _R = _razmer/3.0;
      }
      
      void HotDog::setPosition(float x, float y)
      {
          _x = x;
          _y = y;
      }
      
      void HotDog::paintEvent(QPaintEvent *event)
      {
          QPainter painter(this);
          painter.setRenderHint(QPainter::Antialiasing, true);
      
          painter.setPen(QPen(_color_line, _thickness, Qt::SolidLine));
          // painter.setBrush(QBrush(_color));
          painter.setBrush(QBrush(Qt::NoBrush));
          
          painter.drawRect(_x, _y, _razmer, _razmer); // рамка просто чтоб было
      
          qDebug() << "_my_point.size() " <<_my_point.size();
      
          qreal t=0;
          for(int i =0; _my_point.size() >= i; i++) 
             {
                   painter.drawPoint(_razmer/2+_R*qCos(t), _razmer/2+_R*qSin(t));
                   t+=(2 * M_PI)/_my_point.size();
                   qDebug() << "t" <<t;
             }
      }
      
      void HotDog::mousePressEvent(QMouseEvent *event)
      {
      
      }
      
      void HotDog::mouseReleaseEvent(QMouseEvent *event)
      {
      
      }
      
      void HotDog::moveEvent (QMoveEvent *event)
      {
      	qDebug() << "moveEvent " << "x " << event->pos().x()<< "y " << event->pos().y();
      }
      
      void HotDog::resizeEvent (QResizeEvent *event)
      {
      	qDebug() << "resizeEvent " << "width " << event->size().width()<< "height" << event->size().height();
          //HotDog::paintEvent(QPaintEvent *event);
          repaint();
      }
      
      void HotDog::keyPressEvent(QKeyEvent *event) 
      {
       
       }
      

      Снимок экрана от 2022-08-20 23-37-01.png

      Снимок экрана от 2022-08-20 23-36-59.png

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #3

      @timob256 said in Not redraw when the application is resized:

      void HotDog::resizeEvent (QResizeEvent *event)

      Does not call
      HotDog::setScale(float height, float width)

      so _razmer stay the same.

      1 Reply Last reply
      2
      • timob256T timob256

        does not redraw when the application is resized. :-(

        All code

        main.cpp

        #include "hotdog.h"
        
        #include <QApplication>
        #include <QScreen>
        #include <QDebug>
        
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            HotDog w;
            //выставляем подстройку к размеру экрана
            QSize screenSize = qApp->screens().at(0)->availableSize();
            const int width = screenSize.width() / 2.5;
            const int height = screenSize.height() * 0.5;
            w.setGeometry((screenSize.width() - width) / 2.0,
                          (screenSize.height() - height) / 2.0,
                          width,
                          height);
            w.setWindowTitle("Хот-дог");
            
            w.setScale((float)width, (float)height);
        
            w.show();
            return a.exec();
        }
        

        Hotdog.h

        #ifndef HOTDOG_H
        #define HOTDOG_H
        
        #include <QWidget>
        #include <QPainter>
        #include <QColor>
        #include <QDebug>
        #include <QtMath>
         #include <QKeyEvent>
        
        
        class HotDog : public QWidget {
            Q_OBJECT
        public:
            using QWidget::QWidget;
        
            // туту сетеры  гетеры
            ///
            /// \brief setColor выбор цвета
            ///
            void setColor(int r, int g, int b, int a);
        
            ///
            /// \brief setColor выбор цвета "основной" линии
            ///
            void setColorLine(int r, int g, int b, int a);
        
            ///
            /// \brief setScaleFactor установить коэффициент масштаба
            ///
            void setScale(float height, float width);
        
            ///
            /// \brief setPosition установить расположение обьекта
            ///
            void setPosition(float x, float y);
        
        private:
            // туту слоты
            
            //тут настройки для рисунков и сцены
            QColor   _color            {220, 220, 0, 227};
            QColor   _color_line    {0, 0, 0, 255}; //  ченый не прозрачный
            float    _razmer            {0};        // базовый размер (рамер рисука чтоб не потек) 
            float    _thickness       {0};        // толщина оучки
            float    _x                      {0};
            float    _y                      {0};
            float    _R                      {0};
            
            // тут данные "рисунlка"
            QList <QPointF> _my_point        {50};
            
            
            
        
        
        protected:
            virtual void moveEvent (QMoveEvent *event);           // вызов если окно двигается
            virtual void resizeEvent (QResizeEvent *event);       // вызов если рамер экрана меняется
            virtual void paintEvent(QPaintEvent *event);          // тут рисуем
        //    virtual QSize sizeHint() const;                                        // тут задаем размеры (возми из иного прмера)
            virtual void mousePressEvent(QMouseEvent * event);        // тут нажатие клавиши (зажатие)
            virtual void mouseReleaseEvent(QMouseEvent * event);      // тут зажатие клавиши (отддатие  )
            virtual void keyPressEvent(QKeyEvent *event);             // нажимаем клавиши получаем результат (увеличение и уменьшение чсла точек)
        };
        
        #endif // HOTDOG_H
        

        hotdog.cpp

        #include "hotdog.h"
        
        void HotDog::setColor(int r, int g, int b, int a)
        {
            _color.setRgb(r,g,b,a);
        }
        
        void HotDog::setColorLine(int r, int g, int b, int a)
        {
            _color_line.setRgb(r,g,b,a);
        }
        
        void HotDog::setScale(float height, float width)
        {
            // _height = height;
            //_width = width;
            // тут попробую высчитать базовый размер чтоб неболо растяжения картинки
            if(height > width) 
                 _razmer = width;
            if(width > height) 
                 _razmer = height;
                 
            _thickness = _razmer/50.0;
            _R = _razmer/3.0;
        }
        
        void HotDog::setPosition(float x, float y)
        {
            _x = x;
            _y = y;
        }
        
        void HotDog::paintEvent(QPaintEvent *event)
        {
            QPainter painter(this);
            painter.setRenderHint(QPainter::Antialiasing, true);
        
            painter.setPen(QPen(_color_line, _thickness, Qt::SolidLine));
            // painter.setBrush(QBrush(_color));
            painter.setBrush(QBrush(Qt::NoBrush));
            
            painter.drawRect(_x, _y, _razmer, _razmer); // рамка просто чтоб было
        
            qDebug() << "_my_point.size() " <<_my_point.size();
        
            qreal t=0;
            for(int i =0; _my_point.size() >= i; i++) 
               {
                     painter.drawPoint(_razmer/2+_R*qCos(t), _razmer/2+_R*qSin(t));
                     t+=(2 * M_PI)/_my_point.size();
                     qDebug() << "t" <<t;
               }
        }
        
        void HotDog::mousePressEvent(QMouseEvent *event)
        {
        
        }
        
        void HotDog::mouseReleaseEvent(QMouseEvent *event)
        {
        
        }
        
        void HotDog::moveEvent (QMoveEvent *event)
        {
        	qDebug() << "moveEvent " << "x " << event->pos().x()<< "y " << event->pos().y();
        }
        
        void HotDog::resizeEvent (QResizeEvent *event)
        {
        	qDebug() << "resizeEvent " << "width " << event->size().width()<< "height" << event->size().height();
            //HotDog::paintEvent(QPaintEvent *event);
            repaint();
        }
        
        void HotDog::keyPressEvent(QKeyEvent *event) 
        {
         
         }
        

        Снимок экрана от 2022-08-20 23-37-01.png

        Снимок экрана от 2022-08-20 23-36-59.png

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @timob256 said in Not redraw when the application is resized:

        painter.drawRect(_x, _y, _razmer, _razmer);

        What do you expect when you don't adjust width and height to the acutal widget size?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        timob256T 1 Reply Last reply
        1
        • timob256T timob256

          does not redraw when the application is resized. :-(

          All code

          main.cpp

          #include "hotdog.h"
          
          #include <QApplication>
          #include <QScreen>
          #include <QDebug>
          
          
          int main(int argc, char *argv[])
          {
              QApplication a(argc, argv);
              HotDog w;
              //выставляем подстройку к размеру экрана
              QSize screenSize = qApp->screens().at(0)->availableSize();
              const int width = screenSize.width() / 2.5;
              const int height = screenSize.height() * 0.5;
              w.setGeometry((screenSize.width() - width) / 2.0,
                            (screenSize.height() - height) / 2.0,
                            width,
                            height);
              w.setWindowTitle("Хот-дог");
              
              w.setScale((float)width, (float)height);
          
              w.show();
              return a.exec();
          }
          

          Hotdog.h

          #ifndef HOTDOG_H
          #define HOTDOG_H
          
          #include <QWidget>
          #include <QPainter>
          #include <QColor>
          #include <QDebug>
          #include <QtMath>
           #include <QKeyEvent>
          
          
          class HotDog : public QWidget {
              Q_OBJECT
          public:
              using QWidget::QWidget;
          
              // туту сетеры  гетеры
              ///
              /// \brief setColor выбор цвета
              ///
              void setColor(int r, int g, int b, int a);
          
              ///
              /// \brief setColor выбор цвета "основной" линии
              ///
              void setColorLine(int r, int g, int b, int a);
          
              ///
              /// \brief setScaleFactor установить коэффициент масштаба
              ///
              void setScale(float height, float width);
          
              ///
              /// \brief setPosition установить расположение обьекта
              ///
              void setPosition(float x, float y);
          
          private:
              // туту слоты
              
              //тут настройки для рисунков и сцены
              QColor   _color            {220, 220, 0, 227};
              QColor   _color_line    {0, 0, 0, 255}; //  ченый не прозрачный
              float    _razmer            {0};        // базовый размер (рамер рисука чтоб не потек) 
              float    _thickness       {0};        // толщина оучки
              float    _x                      {0};
              float    _y                      {0};
              float    _R                      {0};
              
              // тут данные "рисунlка"
              QList <QPointF> _my_point        {50};
              
              
              
          
          
          protected:
              virtual void moveEvent (QMoveEvent *event);           // вызов если окно двигается
              virtual void resizeEvent (QResizeEvent *event);       // вызов если рамер экрана меняется
              virtual void paintEvent(QPaintEvent *event);          // тут рисуем
          //    virtual QSize sizeHint() const;                                        // тут задаем размеры (возми из иного прмера)
              virtual void mousePressEvent(QMouseEvent * event);        // тут нажатие клавиши (зажатие)
              virtual void mouseReleaseEvent(QMouseEvent * event);      // тут зажатие клавиши (отддатие  )
              virtual void keyPressEvent(QKeyEvent *event);             // нажимаем клавиши получаем результат (увеличение и уменьшение чсла точек)
          };
          
          #endif // HOTDOG_H
          

          hotdog.cpp

          #include "hotdog.h"
          
          void HotDog::setColor(int r, int g, int b, int a)
          {
              _color.setRgb(r,g,b,a);
          }
          
          void HotDog::setColorLine(int r, int g, int b, int a)
          {
              _color_line.setRgb(r,g,b,a);
          }
          
          void HotDog::setScale(float height, float width)
          {
              // _height = height;
              //_width = width;
              // тут попробую высчитать базовый размер чтоб неболо растяжения картинки
              if(height > width) 
                   _razmer = width;
              if(width > height) 
                   _razmer = height;
                   
              _thickness = _razmer/50.0;
              _R = _razmer/3.0;
          }
          
          void HotDog::setPosition(float x, float y)
          {
              _x = x;
              _y = y;
          }
          
          void HotDog::paintEvent(QPaintEvent *event)
          {
              QPainter painter(this);
              painter.setRenderHint(QPainter::Antialiasing, true);
          
              painter.setPen(QPen(_color_line, _thickness, Qt::SolidLine));
              // painter.setBrush(QBrush(_color));
              painter.setBrush(QBrush(Qt::NoBrush));
              
              painter.drawRect(_x, _y, _razmer, _razmer); // рамка просто чтоб было
          
              qDebug() << "_my_point.size() " <<_my_point.size();
          
              qreal t=0;
              for(int i =0; _my_point.size() >= i; i++) 
                 {
                       painter.drawPoint(_razmer/2+_R*qCos(t), _razmer/2+_R*qSin(t));
                       t+=(2 * M_PI)/_my_point.size();
                       qDebug() << "t" <<t;
                 }
          }
          
          void HotDog::mousePressEvent(QMouseEvent *event)
          {
          
          }
          
          void HotDog::mouseReleaseEvent(QMouseEvent *event)
          {
          
          }
          
          void HotDog::moveEvent (QMoveEvent *event)
          {
          	qDebug() << "moveEvent " << "x " << event->pos().x()<< "y " << event->pos().y();
          }
          
          void HotDog::resizeEvent (QResizeEvent *event)
          {
          	qDebug() << "resizeEvent " << "width " << event->size().width()<< "height" << event->size().height();
              //HotDog::paintEvent(QPaintEvent *event);
              repaint();
          }
          
          void HotDog::keyPressEvent(QKeyEvent *event) 
          {
           
           }
          

          Снимок экрана от 2022-08-20 23-37-01.png

          Снимок экрана от 2022-08-20 23-36-59.png

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #3

          @timob256 said in Not redraw when the application is resized:

          void HotDog::resizeEvent (QResizeEvent *event)

          Does not call
          HotDog::setScale(float height, float width)

          so _razmer stay the same.

          1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            @timob256 said in Not redraw when the application is resized:

            painter.drawRect(_x, _y, _razmer, _razmer);

            What do you expect when you don't adjust width and height to the acutal widget size?

            timob256T Offline
            timob256T Offline
            timob256
            wrote on last edited by
            #4

            @Christian-Ehrlicher HotDog::resizeEvent not working :-(

            mrjjM 1 Reply Last reply
            0
            • timob256T timob256

              @Christian-Ehrlicher HotDog::resizeEvent not working :-(

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @timob256
              so your

              qDebug() << "resizeEvent " << "width " << event->size().width()<< "height" << event->size().height();

              is never seen ?

              1 Reply Last reply
              1
              • timob256T timob256

                does not redraw when the application is resized. :-(

                All code

                main.cpp

                #include "hotdog.h"
                
                #include <QApplication>
                #include <QScreen>
                #include <QDebug>
                
                
                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                    HotDog w;
                    //выставляем подстройку к размеру экрана
                    QSize screenSize = qApp->screens().at(0)->availableSize();
                    const int width = screenSize.width() / 2.5;
                    const int height = screenSize.height() * 0.5;
                    w.setGeometry((screenSize.width() - width) / 2.0,
                                  (screenSize.height() - height) / 2.0,
                                  width,
                                  height);
                    w.setWindowTitle("Хот-дог");
                    
                    w.setScale((float)width, (float)height);
                
                    w.show();
                    return a.exec();
                }
                

                Hotdog.h

                #ifndef HOTDOG_H
                #define HOTDOG_H
                
                #include <QWidget>
                #include <QPainter>
                #include <QColor>
                #include <QDebug>
                #include <QtMath>
                 #include <QKeyEvent>
                
                
                class HotDog : public QWidget {
                    Q_OBJECT
                public:
                    using QWidget::QWidget;
                
                    // туту сетеры  гетеры
                    ///
                    /// \brief setColor выбор цвета
                    ///
                    void setColor(int r, int g, int b, int a);
                
                    ///
                    /// \brief setColor выбор цвета "основной" линии
                    ///
                    void setColorLine(int r, int g, int b, int a);
                
                    ///
                    /// \brief setScaleFactor установить коэффициент масштаба
                    ///
                    void setScale(float height, float width);
                
                    ///
                    /// \brief setPosition установить расположение обьекта
                    ///
                    void setPosition(float x, float y);
                
                private:
                    // туту слоты
                    
                    //тут настройки для рисунков и сцены
                    QColor   _color            {220, 220, 0, 227};
                    QColor   _color_line    {0, 0, 0, 255}; //  ченый не прозрачный
                    float    _razmer            {0};        // базовый размер (рамер рисука чтоб не потек) 
                    float    _thickness       {0};        // толщина оучки
                    float    _x                      {0};
                    float    _y                      {0};
                    float    _R                      {0};
                    
                    // тут данные "рисунlка"
                    QList <QPointF> _my_point        {50};
                    
                    
                    
                
                
                protected:
                    virtual void moveEvent (QMoveEvent *event);           // вызов если окно двигается
                    virtual void resizeEvent (QResizeEvent *event);       // вызов если рамер экрана меняется
                    virtual void paintEvent(QPaintEvent *event);          // тут рисуем
                //    virtual QSize sizeHint() const;                                        // тут задаем размеры (возми из иного прмера)
                    virtual void mousePressEvent(QMouseEvent * event);        // тут нажатие клавиши (зажатие)
                    virtual void mouseReleaseEvent(QMouseEvent * event);      // тут зажатие клавиши (отддатие  )
                    virtual void keyPressEvent(QKeyEvent *event);             // нажимаем клавиши получаем результат (увеличение и уменьшение чсла точек)
                };
                
                #endif // HOTDOG_H
                

                hotdog.cpp

                #include "hotdog.h"
                
                void HotDog::setColor(int r, int g, int b, int a)
                {
                    _color.setRgb(r,g,b,a);
                }
                
                void HotDog::setColorLine(int r, int g, int b, int a)
                {
                    _color_line.setRgb(r,g,b,a);
                }
                
                void HotDog::setScale(float height, float width)
                {
                    // _height = height;
                    //_width = width;
                    // тут попробую высчитать базовый размер чтоб неболо растяжения картинки
                    if(height > width) 
                         _razmer = width;
                    if(width > height) 
                         _razmer = height;
                         
                    _thickness = _razmer/50.0;
                    _R = _razmer/3.0;
                }
                
                void HotDog::setPosition(float x, float y)
                {
                    _x = x;
                    _y = y;
                }
                
                void HotDog::paintEvent(QPaintEvent *event)
                {
                    QPainter painter(this);
                    painter.setRenderHint(QPainter::Antialiasing, true);
                
                    painter.setPen(QPen(_color_line, _thickness, Qt::SolidLine));
                    // painter.setBrush(QBrush(_color));
                    painter.setBrush(QBrush(Qt::NoBrush));
                    
                    painter.drawRect(_x, _y, _razmer, _razmer); // рамка просто чтоб было
                
                    qDebug() << "_my_point.size() " <<_my_point.size();
                
                    qreal t=0;
                    for(int i =0; _my_point.size() >= i; i++) 
                       {
                             painter.drawPoint(_razmer/2+_R*qCos(t), _razmer/2+_R*qSin(t));
                             t+=(2 * M_PI)/_my_point.size();
                             qDebug() << "t" <<t;
                       }
                }
                
                void HotDog::mousePressEvent(QMouseEvent *event)
                {
                
                }
                
                void HotDog::mouseReleaseEvent(QMouseEvent *event)
                {
                
                }
                
                void HotDog::moveEvent (QMoveEvent *event)
                {
                	qDebug() << "moveEvent " << "x " << event->pos().x()<< "y " << event->pos().y();
                }
                
                void HotDog::resizeEvent (QResizeEvent *event)
                {
                	qDebug() << "resizeEvent " << "width " << event->size().width()<< "height" << event->size().height();
                    //HotDog::paintEvent(QPaintEvent *event);
                    repaint();
                }
                
                void HotDog::keyPressEvent(QKeyEvent *event) 
                {
                 
                 }
                

                Снимок экрана от 2022-08-20 23-37-01.png

                Снимок экрана от 2022-08-20 23-36-59.png

                timob256T Offline
                timob256T Offline
                timob256
                wrote on last edited by
                #6

                @timob256

                Code it's working

                hotdog.cpp

                 ...
                 void HotDog::resizeEvent (QResizeEvent *event)
                 {
                     qDebug() << "resizeEvent " << "width " << event->size().width()<< "height" << event->size().height();
                        //HotDog::paintEvent(QPaintEvent *event);
                         setScale(event->size().width(), event->size().height());
                         repaint();
                 }
                
                mrjjM 1 Reply Last reply
                0
                • timob256T timob256

                  @timob256

                  Code it's working

                  hotdog.cpp

                   ...
                   void HotDog::resizeEvent (QResizeEvent *event)
                   {
                       qDebug() << "resizeEvent " << "width " << event->size().width()<< "height" << event->size().height();
                          //HotDog::paintEvent(QPaintEvent *event);
                           setScale(event->size().width(), event->size().height());
                           repaint();
                   }
                  
                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @timob256
                  It still stay same size ?

                  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