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 draw on other QWidgets?
QtWS25 Last Chance

how to draw on other QWidgets?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.8k Views
  • 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.
  • T Offline
    T Offline
    TomNow99
    wrote on 4 Sept 2020, 11:42 last edited by TomNow99 9 Apr 2020, 11:44
    #1

    Hello,

    What I have:

    have.png

    What I want:

    want.png

    My code in mainWindow:

    void MainWindow::paintEvent(QPaintEvent *event)
    {
        QPainter painter(this);
        painter.drawLine(0,0,100,100);
        QMainWindow::paintEvent(event);
    }
    

    I try with:

    button -> setAttribute(Qt::WA_PaintOnScreen);
    

    but with no result.

    Is there a simple way to draw like in the second picture?

    EDIT:
    Button is added to mainWindow using mainwindow.ui

    M 1 Reply Last reply 4 Sept 2020, 11:48
    0
    • T TomNow99
      4 Sept 2020, 11:42

      Hello,

      What I have:

      have.png

      What I want:

      want.png

      My code in mainWindow:

      void MainWindow::paintEvent(QPaintEvent *event)
      {
          QPainter painter(this);
          painter.drawLine(0,0,100,100);
          QMainWindow::paintEvent(event);
      }
      

      I try with:

      button -> setAttribute(Qt::WA_PaintOnScreen);
      

      but with no result.

      Is there a simple way to draw like in the second picture?

      EDIT:
      Button is added to mainWindow using mainwindow.ui

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 4 Sept 2020, 11:48 last edited by mrjj 9 Apr 2020, 11:48
      #2

      @TomNow99

      Hi
      You cannot draw on other widgets.

      However, you can use a 100% transparent overlay
      widget and draw on that one and it will be over the other widgets.
      So you use its paintEvent to draw the lines you want.
      https://stackoverflow.com/questions/19199863/draw-rectangular-overlay-on-qwidget-at-click

      But what is the goal of this ?

      1 Reply Last reply
      1
      • T Offline
        T Offline
        TomNow99
        wrote on 4 Sept 2020, 11:57 last edited by TomNow99 9 Apr 2020, 12:00
        #3

        @mrjj The goal is very interesting… :D

        I use Win 10 and when I click for example on the clock ( on the right in taskbar ) and I move mouse on the calendar ( popup when click on clock ) I see that the light is changed. Picture:

        win.png

        My mouse is on the center of 24 day. So the red circle is very close this day and the edges are very highlighted. The green is not as close like the red one, so edges are less highlighted, and the blue circle ( half circle :) ) is not close, so there is no highlighted. I would like do the same in QT .

        And this is not as simple as you can think. When I move mouse in this 24 square I change other square days. When I move mouse coursor to the bottom left corner I more highlighted 30 ( cursor is still in 24 square ). When I move to top left corner I more highlighted 16 square. Try it :D

        M 1 Reply Last reply 4 Sept 2020, 12:04
        0
        • T TomNow99
          4 Sept 2020, 11:57

          @mrjj The goal is very interesting… :D

          I use Win 10 and when I click for example on the clock ( on the right in taskbar ) and I move mouse on the calendar ( popup when click on clock ) I see that the light is changed. Picture:

          win.png

          My mouse is on the center of 24 day. So the red circle is very close this day and the edges are very highlighted. The green is not as close like the red one, so edges are less highlighted, and the blue circle ( half circle :) ) is not close, so there is no highlighted. I would like do the same in QT .

          And this is not as simple as you can think. When I move mouse in this 24 square I change other square days. When I move mouse coursor to the bottom left corner I more highlighted 30 ( cursor is still in 24 square ). When I move to top left corner I more highlighted 16 square. Try it :D

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 4 Sept 2020, 12:04 last edited by
          #4

          @TomNow99
          Hi
          Ohh so its not so much lines you want to draw
          but fade out the borders depending on the distance?

          I dont have such a calendar in my win 10 so not 100% sure how it looks like but
          is it a custom control you want to do this with or plain normal buttons ?

          1 Reply Last reply
          1
          • T Offline
            T Offline
            TomNow99
            wrote on 4 Sept 2020, 12:19 last edited by TomNow99 9 Apr 2020, 12:26
            #5

            @mrjj No. I don't need any lines. But I think about circles which I will draw on QLabels like this:

            ex.png

            The biggest rect is mainWindow. The smaller are QLabels. The red "X" is position of my mouse cursor. I was thinking about something like that.

            The same effect like in the calendar is in Microsoft Edge.

            I would like to do it using only QT. Of course I know that my project will be ugly :D

            EDIT:
            I can count the distance from my current cursor mouse position to other points in mainWindow and print on all widgets ( QPainter and paintEvent ) which have one or more points, which distance is smaller than distance which I would like ( for example radius = 20 ) ( of course I should have more than one radius - the closest points will have other color than the points which aren't not so close ). But I think there is a better solution.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 4 Sept 2020, 12:34 last edited by
              #6

              Hi
              Im not sure it will look good but you can try it :)

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TomNow99
                wrote on 4 Sept 2020, 12:57 last edited by
                #7

                For other people, who look for the situation from my first post:

                pushButton->setStyleSheet("QPushButton{background: transparent;}");
                
                1 Reply Last reply
                0
                • L LRDPRDX referenced this topic on 28 Mar 2024, 11:22

                5/7

                4 Sept 2020, 12:19

                • Login

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