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. Putting other widgets inside a QPushButton
Forum Updated to NodeBB v4.3 + New Features

Putting other widgets inside a QPushButton

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.3k 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.
  • C Offline
    C Offline
    cuddlykittens11
    wrote on last edited by
    #1

    I'm trying to make a widget that represents a layer in an image, then when the user clicks it, the widget will be "selected." But I also want there to me some other widgets inside the widget to edit things about the image. I'm wondering if it's possible to put other widgets inside a QPushButton?

    I already tried having a QWidget sublass and overloading QWidget::mousePressEvent() and already had some issues propigating the events to the inside widgets.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      [quote author="cuddlykittens11" date="1422550102"]I already tried having a QWidget sublass and overloading QWidget::mousePressEvent() and already had some issues propigating the events to the inside widgets.[/quote]

      propagating works in the other direction around. Meaning when your parent/container widget receives the mouse-event it wasn't accepted from your child widget (if the event happend at the child widgets pos).

      So don't use a QPushButton and place widgets inside it. What widgets did you place inside the widget which didn't work?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cuddlykittens11
        wrote on last edited by
        #3

        QPushButtons, QSpinBoxes, and QLineEdits. I also tried using a QGraphicsProxyWidget sublcass, and then placing the widgets inside of a QGraphicsScene. It didn't work out too well.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          you have to be more specific than that.
          What didn't work? What did you try exactly?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cuddlykittens11
            wrote on last edited by
            #5

            Okay, maybe a picture will help illustrate. I'm trying to make a widget to select and modify layers in an image. Here's a bad little mockup:

            !http://i.imgur.com/xQjqz5B.png(mockup)!

            I was thinking that I could represent each layer as a widget (display info like resolution for that layer), but also have some buttons inside the widget to modify the cel (e.g. show/hide layer with a QCheckBox or delete layer with a QPushButton). But I also want the user to select the current layer by clicking on the area that isn't another widget.

            I tried acomplishing this via a subclass of QGraphicsProxyWidget, but I have many issues when it game to event propigation.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              What you have there is a list of items. Wouldn't it make sense to use something that is meant for displaying just that?

              Do you really want to have this inside a graphics view (you mentioned QGraphicsProxyWidget), or could it just be a widget? Or perhaps a Quick scene? What version of Qt are you on?

              Anyway: just because you need to handle a mouse click, it doesn't mean that you have to subclass QPushButton or put other things on top of it. Don't do that.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cuddlykittens11
                wrote on last edited by
                #7

                I'm running Qt5. Would it be possible to use a "QListwidget":http://qt-project.org/doc/qt-4.8/qlistwidget.html or one of its parent classes to acchive this?

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  yes can be. But you should only use it if you just want to display a few (not to many) widgets inside it.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cuddlykittens11
                    wrote on last edited by
                    #9

                    how many would be "not too many"? Would 50-100 be too much.

                    As a possible solution to this problem, I was thinking about subclassing QGraphicsObject and making clickable areas (e.g. the Delte button up there) that will perform actions.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      Putting widgets inside item views is not ideal. It doesn't scale well, and it is a bit of a hassle. This works much better with Quick, where a delegate may contain anything you want, including Quick controls. Perhaps you could use a Quick scene to display your list on a QQuickWidget (available from Qt 5.3).

                      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