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. How to make a rectangles filled with horizontal lines in a QGraphicsView?

How to make a rectangles filled with horizontal lines in a QGraphicsView?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.3k Views 3 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by A Former User
    #1

    How to make a rectangle filled with horizontal lines in a QGraphicsView for example as follows?

    _________________________
    |-----------------------------------|
    |----------------------------------  |
    |----------------------------------  |
    | ----------------------------------  |
    | ---------------------------------- |
    | ---------------------------------- |
    | ----------------------------------|
    |------------------------------------
    
    A 1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Create a custom QGraphicsItem-derived class, override boundingRect() and paint(), draw the background, draw the lines with a dashed pen style.

      • QGraphicsItem Class, see example under #details
      • QPainter Class
      • QPen
      • enum Qt::PenStyle
      • QBrush
      • enum Qt::BrushStyle
      • Basic Drawing Example
      1 Reply Last reply
      1
      • Q Qt Enthusiast

        How to make a rectangle filled with horizontal lines in a QGraphicsView for example as follows?

        _________________________
        |-----------------------------------|
        |----------------------------------  |
        |----------------------------------  |
        | ----------------------------------  |
        | ---------------------------------- |
        | ---------------------------------- |
        | ----------------------------------|
        |------------------------------------
        
        A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        @Qt-Enthusiast
        Depending on what exactly you want, it may be sufficient to apply the correct brush.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #4

          could you elaborate with the QBrush color style

          A 1 Reply Last reply
          0
          • Q Qt Enthusiast

            could you elaborate with the QBrush color style

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            @Qt-Enthusiast
            Create a QBrush and set the style to Qt::HorPattern

            myBrush.setStyle(Qt::HorPattern)
            

            Then apply the brush to a rectangle. You can see the result in the Basic Drawing example.

            1 Reply Last reply
            1

            • Login

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