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. Overlapping widgets

Overlapping widgets

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 763 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.
  • S Offline
    S Offline
    SteveFalco
    wrote on last edited by
    #1

    I'm a new user of Qt, and I have a question about overlapping widgets. I've been working on a calculator project: https://gitlab.com/stevenfalco/hp67-emulator

    I've gotten it working, but now I want to be able to scale the mainwindow. I have a number of overlapping widgets:

    There is a QLabel covering the whole centralwidget - it shows the background image of the calculator.

    There are also three QGridLayouts for the various QPushbuttons, but those layouts are not in a vertical stack, because I wanted to fine-tune the placement.

    I also have an overlap of a QPushbutton (called "card") and a QGraphicsView (called "card_view"). The "card" pushbutton is on top, and is transparent, so the user just sees the "card_view" underneath it.

    Similarly, I have some overlapped buttons and graphics views for the slide switches at the top of the calculator.

    I'd like to restructure this to be more in line with a proper layout, but I'm not sure how to go about it.

    I could also consider getting rid of all the buttons and just handle mouse events myself, but that feels like a bad design, and I'd still need to overlap the various graphics views with the underlying background image.

    Please let me know what would be a suitable design, as I am very new to Qt, and to C++ also.

    JonBJ Pl45m4P 2 Replies Last reply
    0
    • S SteveFalco

      I'm a new user of Qt, and I have a question about overlapping widgets. I've been working on a calculator project: https://gitlab.com/stevenfalco/hp67-emulator

      I've gotten it working, but now I want to be able to scale the mainwindow. I have a number of overlapping widgets:

      There is a QLabel covering the whole centralwidget - it shows the background image of the calculator.

      There are also three QGridLayouts for the various QPushbuttons, but those layouts are not in a vertical stack, because I wanted to fine-tune the placement.

      I also have an overlap of a QPushbutton (called "card") and a QGraphicsView (called "card_view"). The "card" pushbutton is on top, and is transparent, so the user just sees the "card_view" underneath it.

      Similarly, I have some overlapped buttons and graphics views for the slide switches at the top of the calculator.

      I'd like to restructure this to be more in line with a proper layout, but I'm not sure how to go about it.

      I could also consider getting rid of all the buttons and just handle mouse events myself, but that feels like a bad design, and I'd still need to overlap the various graphics views with the underlying background image.

      Please let me know what would be a suitable design, as I am very new to Qt, and to C++ also.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @SteveFalco
      I think what you are saying is that you have a background image of the calculator on which everything has to be positioned. You then overlap widgets and place transparent buttons, in layouts, in order to interact with the image.

      I wonder whether you would be happier with a QGraphicsScene/View, perhaps with the image set as the background, on which you detect click areas and/or place graphics objects? Widgets and layouts are great for abstract positioning, resizing, scaling, but not for ensuring items are at specified positions.

      S 1 Reply Last reply
      1
      • JonBJ JonB

        @SteveFalco
        I think what you are saying is that you have a background image of the calculator on which everything has to be positioned. You then overlap widgets and place transparent buttons, in layouts, in order to interact with the image.

        I wonder whether you would be happier with a QGraphicsScene/View, perhaps with the image set as the background, on which you detect click areas and/or place graphics objects? Widgets and layouts are great for abstract positioning, resizing, scaling, but not for ensuring items are at specified positions.

        S Offline
        S Offline
        SteveFalco
        wrote on last edited by
        #3

        @JonB - That feels like the right way to go. I suspect it would make resizing the window simpler. I need to learn more about QGraphicsScene/View, so I'll play around with that approach and see how it works out. Thanks!

        1 Reply Last reply
        0
        • S SteveFalco

          I'm a new user of Qt, and I have a question about overlapping widgets. I've been working on a calculator project: https://gitlab.com/stevenfalco/hp67-emulator

          I've gotten it working, but now I want to be able to scale the mainwindow. I have a number of overlapping widgets:

          There is a QLabel covering the whole centralwidget - it shows the background image of the calculator.

          There are also three QGridLayouts for the various QPushbuttons, but those layouts are not in a vertical stack, because I wanted to fine-tune the placement.

          I also have an overlap of a QPushbutton (called "card") and a QGraphicsView (called "card_view"). The "card" pushbutton is on top, and is transparent, so the user just sees the "card_view" underneath it.

          Similarly, I have some overlapped buttons and graphics views for the slide switches at the top of the calculator.

          I'd like to restructure this to be more in line with a proper layout, but I'm not sure how to go about it.

          I could also consider getting rid of all the buttons and just handle mouse events myself, but that feels like a bad design, and I'd still need to overlap the various graphics views with the underlying background image.

          Please let me know what would be a suitable design, as I am very new to Qt, and to C++ also.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @SteveFalco said in Overlapping widgets:

          There are also three QGridLayouts for the various QPushbuttons

          A quick QoL improvement/reducing LoC:
          I checked the repo out nd noticed that you have over 130 lines of code just to connect all buttons to the same two signals (calculatorButtonClicked and -Released).
          It can save at least 100 lines if you group all buttons in one container and connect each button to these two signals while iterating.
          You could also work with QButtonGroup or use QSignalMapper.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          S 1 Reply Last reply
          1
          • Pl45m4P Pl45m4

            @SteveFalco said in Overlapping widgets:

            There are also three QGridLayouts for the various QPushbuttons

            A quick QoL improvement/reducing LoC:
            I checked the repo out nd noticed that you have over 130 lines of code just to connect all buttons to the same two signals (calculatorButtonClicked and -Released).
            It can save at least 100 lines if you group all buttons in one container and connect each button to these two signals while iterating.
            You could also work with QButtonGroup or use QSignalMapper.

            S Offline
            S Offline
            SteveFalco
            wrote on last edited by
            #5

            @Pl45m4 I'll look into your suggestions. I haven't learned about iterators yet. :-)

            Pl45m4P 1 Reply Last reply
            0
            • S SteveFalco

              @Pl45m4 I'll look into your suggestions. I haven't learned about iterators yet. :-)

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @SteveFalco said in Overlapping widgets:

              I haven't learned about iterators yet. :-)

              I dont say you have to use a "real" iterator.
              There is this mysterious thing called for loop :-)


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              1
              • S SteveFalco has marked this topic as solved on

              • Login

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