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. Unable to view rectangle(red color) drawn using Qpainter when the window background is set to black color

Unable to view rectangle(red color) drawn using Qpainter when the window background is set to black color

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 917 Views 2 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.
  • K Offline
    K Offline
    kshp
    wrote on last edited by
    #1

    i want to draw a red color rectangle on a black backgrounded window but unable to view the rectangle. My code is as below:

    void MainWindow::paintEvent(QPaintEvent *e)
    {
    QPainter painter(this);

    QPen linepen(Qt::red);
    linepen.setWidth(5);

    painter.setPen(linepen);

    painter.drawRect(230,120,121,71);
    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      The pen is used for the lines and outlines. If you want to have a rect in red, either use a red brush or use the fillRect function.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kshp
        wrote on last edited by kshp
        #3

        Using red brush or fillRect is making inner part of the rectangle also filled up with red color. I want only the border of the rectangle to be filled with red and inner part to be transparent.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then set the brush to Qt::transparent.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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