Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    3
    5
    2168
    Loading More Posts
    • 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
      EdOfTheMountain last edited by

      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 Reply Quote 0
      • E
        Eddy last edited by

        Have a look at the sources.

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

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply Reply Quote 0
        • E
          EdOfTheMountain last edited by

          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 Reply Quote 0
          • A
            andreyc last edited by

            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 Reply Quote 0
            • E
              EdOfTheMountain last edited by

              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 Reply Quote 0
              • First post
                Last post