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. [SOLVED] How is background grid drawn in Qt 4.8 undo example (see screenshot) ?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.3k 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.
  • E Offline
    E Offline
    EdOfTheMountain
    wrote on last edited by
    #1

    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?

    • http://qt-project.org/doc/qt-4.8/demos-undo.html

    See screen shot below:

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

    Thanks in advance,

    -Ed

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Have a look at the sources.

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

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • E Offline
        E Offline
        EdOfTheMountain
        wrote on last edited by
        #3

        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);
        

        }

        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          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."

          1 Reply Last reply
          0
          • E Offline
            E Offline
            EdOfTheMountain
            wrote on last edited by
            #5

            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

            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