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. Can i multiply inherite from QGraphicsItem and QHBoxLayout?
Forum Updated to NodeBB v4.3 + New Features

Can i multiply inherite from QGraphicsItem and QHBoxLayout?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.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.
  • O Offline
    O Offline
    opengpu
    wrote on last edited by
    #1

    can i multiply inherite from QGraphicsItem and QHBoxLayout?
    i tried, and then I add this "layout" on a dialog, and then set this dialog to QGraphicsProxyWidget by setWidget().
    but overriden pain(), mousePressEvent() and so on does not work...
    ps. if i can't inherite from QGraphicsItem and QHBoxLayout, so how should i do if i want to add some controls on the QGraphicsItem as well as the background can be painted by myself.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      opengpu
      wrote on last edited by
      #2

      i tried inherite from QWidget and QGraphicsItem, but there seems to have many ambiguis func with same name...

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vikaspachdha
        wrote on last edited by
        #3

        What's wrong with composition? Inheritance is not a solution to everything. To get a flying rat one should not have a class inherited from rat and wings rather wings should be composed in inheritance of rat.

        1 Reply Last reply
        0
        • O Offline
          O Offline
          opengpu
          wrote on last edited by
          #4

          but i don't know whether a QHBoxLayout can be added into a QGraphicsItem...
          what i need is to render the QGraphicsItem as background as well as some controls(eg.label, editbox, etc) on it. what is the best way to do this?
          thank you.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vikaspachdha
            wrote on last edited by
            #5

            @
            QApplication a(argc, argv);

            QGroupBox *groupBox = new QGroupBox("Contact Details");
            QLabel *numberLabel = new QLabel("Telephone number");
            QLineEdit *numberEdit = new QLineEdit;
            
            QFormLayout *layout = new QFormLayout;
            layout->addRow(numberLabel, numberEdit);
            groupBox->setLayout(layout);
            
            QGraphicsScene scene;
            QPixmap pixmap(600,200);
            pixmap.fill(Qt::blue);
            QGraphicsPixmapItem* pixmapItem = scene.addPixmap(pixmap);
            QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(pixmapItem);
            proxy->setWidget(groupBox);
            
            QGraphicsView view(&scene);
            view.show();
            
            return a.exec();
            

            @

            I hope this gives you an idea.

            1 Reply Last reply
            0
            • O Offline
              O Offline
              opengpu
              wrote on last edited by
              #6

              thank you, and i will try.
              what i want is in this link: "":http://qt-project.org/forums/viewthread/45769/
              and as the code u give, i can get the item in the big rect node...but how can i add many item as ur code together in the big rect node? and these item would better to be on sth like the "layout"

              1 Reply Last reply
              0
              • O Offline
                O Offline
                opengpu
                wrote on last edited by
                #7

                i tried ur code, have a problem...pixmap.fill(Qt::blue); seems meanless..cause the whole rect have covered by the layout...
                BTW, as i said above, actually i want to use the QGraphicsItem as a backgound where i can add some controls on it. meanwhile, when i click the area which is not covered by the controls but on the QGraphicsItem, i want to handle the mouse event in my custom QGraphicsItem class(or can i get this through set some controls disable?)
                thank you

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  opengpu
                  wrote on last edited by
                  #8

                  ...

                  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