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. I have a problem with painting my squares are the wrong size

I have a problem with painting my squares are the wrong size

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 198 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.
  • A Offline
    A Offline
    AI_Messiah
    wrote on last edited by
    #1

    MyScreen2021-08-02_1_04_17_PM.jpg

    I made things bigger so they are easier to see. I want the space between filled in;

    I have a widget promoted to a class for the painting.
    header:

    #ifndef RENDERER_H
    #define RENDERER_H
    
    #include <QWidget>
    #include <QPaintEvent>
    #include <QPainter>
    class Renderer : public QWidget
    {
        Q_OBJECT
    public:
        explicit Renderer(QWidget *parent = nullptr);
        QSize minimumSizeHint() const Q_DECL_OVERRIDE;
        QSize sizeHint() const Q_DECL_OVERRIDE;
        bool isFill[400][400];
    protected:
        void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
    signals:
    
    };
    
    #endif // RENDERER_H
    
    

    source:

    #include "renderer.h"
    
    Renderer::Renderer(QWidget *parent) : QWidget(parent)
    {
        for (int y=0;y<400;y++){
            for (int x=0;x<400;x++) isFill[x][y] = false;
        }
        for (int i=40;i<60;i++) isFill[i][50] = true;
    }
    
    QSize Renderer::minimumSizeHint() const
    {
        return QSize(100,100);
    }
    
    QSize Renderer::sizeHint() const
    {
        return QSize(400,400);
    }
    
    void Renderer::paintEvent(QPaintEvent *event)
    {
        QPainter paint(this);
        paint.setBrush(QColor(0, 0, 0, 255));
        //paint.setRenderHint(QPainter::Antialiasing, true);
        paint.drawRect(this->rect());
        paint.setBrush(QColor(255, 255, 255, 255));
        for (int y=0;y<100;y++){
            for (int x=0;x<100;x++) if(isFill[x][y]) paint.drawRect(x * 8, y * 8, 8, 8);
        }
    }
    
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      AI_Messiah
      wrote on last edited by
      #2

      I wanb\t the spaces filled in.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        drawRect() uses a brush for the inside of the rectangle and a pen for the border. A pen is by default black so that's why you're seeing the borders. Either set a white pen on the painter or, better yet, use fillRect() instead of drawRect(), which only fills the rectangle with a brush and has no border.

        1 Reply Last reply
        2

        • Login

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