Nominate our 2022 Qt Champions!

Can i multiply inherite from QGraphicsItem and QHBoxLayout?

  • 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.

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

  • 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.

  • 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.

  • @
    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);
    QGraphicsScene scene;
    QPixmap pixmap(600,200);
    QGraphicsPixmapItem* pixmapItem = scene.addPixmap(pixmap);
    QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(pixmapItem);
    QGraphicsView view(&scene);;
    return a.exec();


    I hope this gives you an idea.

  • thank you, and i will try.
    what i want is in this link: "":
    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"

  • 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

  • ...

Log in to reply