Qt creator: Widget [SOLVED]



  • Is there the possibility to specify the dimesion of a QWidget to be something like the 80% of the size of the parent?



  • There are QWidget properties that can be used here -> size, height, width. So you could do something like
    @
    myWidget -> setSize( QSize( (parentWidget->height() * 4 / 5), (parentWidget->width() * 4 / 5) ) )
    @



  • The "easy" solution would be to just get the size of the parent - using getSize() or width(),height() member fns - and set the size of your widget to be 80% of that. Something like this:
    @
    QWidget* parent = new QWidget();
    QWidget* myWidget = new QWidget(parent);
    myWidget->setFixedSize(parent->width()*0.8, parent->height()*0.8);@

    If your parent widget is resizable, you may need to subclass QWidget for your child widget and reimplement resizeEvent().

    EDIT: myWidget->resize() is probably better than myWidget->setFixedSize().



  • ok, thank you. How can I add a QWidget to a QGraphicsView?



  • You probably need to add it to the corresponding QGraphicsScene of the QGraphicsView, using e.g. @ QGraphicsScene::addWidget(myWidget) @



  • Adding widgets to grahpics views, although possible, is probably not a good idea. It never worked all that well...



  • So where can I add it ? To the QGraphicsScene?

    Thank you



  • No, I meant using widgets in the QGraphicsView framework (including *Scene) should be avoided if possible. It may work for you, but chances are you'll run into gliches and/or performance issues.



  • It is true. I am experimenting permformance issue. So where should I add it?

    ty


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.