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
Forum Updated to NodeBB v4.3 + New Features

Not redraw when the application is resized

Scheduled Pinned Locked Moved Solved General and Desktop
2d graphicsevent
7 Posts 3 Posters 814 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.
  • T Offline
    T Offline
    timob256
    wrote on 21 Aug 2022, 12:37 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 T 3 Replies Last reply 21 Aug 2022, 12:39
    0
    • T timob256
      21 Aug 2022, 12:37

      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 21 Aug 2022, 12:43 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
      • T timob256
        21 Aug 2022, 12:37

        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 21 Aug 2022, 12:39 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

        T 1 Reply Last reply 21 Aug 2022, 12:50
        1
        • T timob256
          21 Aug 2022, 12:37

          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 21 Aug 2022, 12:43 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
            21 Aug 2022, 12:39

            @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?

            T Offline
            T Offline
            timob256
            wrote on 21 Aug 2022, 12:50 last edited by
            #4

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

            mrjjM 1 Reply Last reply 21 Aug 2022, 12:52
            0
            • T timob256
              21 Aug 2022, 12:50

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 21 Aug 2022, 12:52 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
              • T timob256
                21 Aug 2022, 12:37

                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

                T Offline
                T Offline
                timob256
                wrote on 21 Aug 2022, 16:14 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 21 Aug 2022, 16:39
                0
                • T timob256
                  21 Aug 2022, 16:14

                  @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 21 Aug 2022, 16:39 last edited by
                  #7

                  @timob256
                  It still stay same size ?

                  1 Reply Last reply
                  0

                  1/7

                  21 Aug 2022, 12:37

                  • Login

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