Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] How is background grid drawn in Qt 4.8 undo example (see screenshot) ?



  • I am need to create a drawing app that supports undo and a grid that can be scaled to meters, or feet.

    How is the background grid drawn in the Qt 4.8 Undo example?

    See screen shot below:

    !http://qt-project.org/doc/qt-4.8/images/undodemo.png(Screenshot Qt4.8 Undo Example)!

    Thanks in advance,

    -Ed



  • Have a look at the sources.

    @
    pal.setBrush(QPalette::Base, QPixmap(":/icons/background.png"));
    @



  • How does the background.png image, which is a 20 pixel x 20 pixel white block, create a blue grid pattern on a white background?

    @
    /******************************************************************************
    ** Document
    */

    Document::Document(QWidget *parent)
    : QWidget(parent), m_currentIndex(-1), m_mousePressIndex(-1), m_resizeHandlePressed(false)
    {
    m_undoStack = new QUndoStack(this);

    setAutoFillBackground(true);
    setBackgroundRole(QPalette::Base);
    
    QPalette pal = palette();
    pal.setBrush(QPalette::Base, QPixmap(":/icons/background.png"));
    pal.setColor(QPalette::HighlightedText, Qt::red);
    setPalette(pal);
    

    }

    @



  • If you zoom in you will see that background.png is not a white block.
    It has two blue borders.

    @
    pal.setBrush(QPalette::Base, QPixmap(":/icons/background.png"));
    @
    uses a function "QPalette::setBrush":http://qt-project.org/doc/qt-5/qpalette.html#setBrush with the following signature
    @
    void QPalette::setBrush(ColorRole role, const QBrush & brush)
    @
    It calls "QBrush::QBrush":http://qt-project.org/doc/qt-5/qbrush.html#QBrush-7 contructructor
    @
    QBrush::QBrush(const QPixmap & pixmap)
    @
    "Constructs a brush with a black color and a texture set to the given pixmap. The style is set to "Qt::TexturePattern":http://qt-project.org/doc/qt-5/qt.html#BrushStyle-enum."



  • Thank you Eddy and Andre.

    I zoomed into the 20 pixel square background.png image and saw that you are correct. There is a one pixel blue border on both right and bottom sides. I did not expect a grid to be implemented using an image like this.

    I bet there are many useful background effects that could be accomplished using this technique. Thank you both for enlightening me.

    -Ed


Log in to reply