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 to fill the widget's background like this,.Please help
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to fill the widget's background like this,.Please help

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 5.5k 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.
  • L Offline
    L Offline
    Lucky Dog
    wrote on last edited by
    #1

    !http://www.pconline.com.cn/pcedu/sj/pm/photoshop/rm/0510/pic/051012pscdcvr83-04.jpg(this is the background)!

    How should i fill the background like the photoshop's edit window on QWidget? I mean draw the lightgray and white squre alternately. Please help me.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      steno
      wrote on last edited by
      #2

      Do it in the paint event, and just draw a rectangles.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        iunknwn
        wrote on last edited by
        #3

        Also look into

        QBrush::setStyle ( Qt::BrushStyle style )

        Qt::TexturePattern

        QBrush::setTexture ( const QPixmap & pixmap )

        Vista x64 with Qt 4.8.2 and VS2010

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Lucky Dog
          wrote on last edited by
          #4

          Thank you for your help. I have solved my problem like this
          @
          QSize sz(40,40);
          QPixmap pix(sz);
          QPainter p(&pix);
          p.fillRect(0,0,sz.width()/2,sz.height()/2,Qt::lightGray);
          p.fillRect(sz.width()/2,0,sz.width()/2,sz.height()/2,Qt::white);
          p.fillRect(0,sz.height()/2,sz.width()/2,sz.height()/2,Qt::white);
          p.fillRect(sz.width()/2,sz.height()/2,sz.width()/2,sz.height()/2,Qt::lightGray);
          this->setBackgroundBrush(QBrush(pix));
          @

          [edit: code highlighting added / Denis Kormalev]

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            Would you mind wrapping that into code tags, please? Thanks!

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Lucky Dog
              wrote on last edited by
              #6

              Sorry, my bad

              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