[Qt-interest] nesting QGraphicsview inside QWidget

Martin Schröer gordon at gordonswelt.de
Sun Mar 8 17:36:04 CET 2009


Yes, adding

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(&view);
    setLayout(mainLayout);
    view.show();

did the trick.

Now, there's another problem:
while now being embedded in a widget, the view refuses to dynamically 
change size,
it displays its contents ignoring the widget size.

view.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
and friends also chage nothing.



Luc Devallonné schrieb:
> Martin,
>
> The problem is that the QGraphicsView is no added to any layout, may
> want to try something like
>
> layout()->addWidget(&view) before the show() in the init()
>
> Luc
>
> On Sun, Mar 8, 2009 at 4:40 PM, Martin Schröer <gordon at gordonswelt.de> wrote:
>   
>> Here we go:
>>
>> the GraphicsView is nested inside imemMediaWidget class, which is used in
>> the main app:
>>
>>   mediaWid = new imemMediaWidget();
>>     QGridLayout *mainLayout = new QGridLayout;
>>   mainLayout->addWidget(loadButton);
>>   mainLayout->addWidget(mediaWid, 1, 0, 1, 2);
>>   // mainLayout->addWidget(videoWidget, 1, 0);
>>   // mainLayout->addWidget(mediaWid, 1, 1);
>> mainLayout->addWidget(infoButton, 2, 0);
>>   mainLayout->addWidget(timeLabel, 2, 1);
>>   mainLayout->addWidget(infoLabel,3, 0, 1, 2);
>>   setLayout(mainLayout);
>>
>> the widget itself:
>>
>> <header>
>>
>> class imemMediaWidget : public QWidget
>> {
>>   Q_OBJECT
>>   QGraphicsScene scene;
>>   QGraphicsView view;
>>  public:
>>   imemMediaWidget(QWidget *parent = 0);
>>  protected:
>>  private:
>>   void init();
>>   CustomProxy *proxy;
>>  private slots:    };
>>
>> plus it's implementation ( stripped ):
>>
>> #include "imemMediaWidget.h"
>>
>>
>> imemMediaWidget::imemMediaWidget(QWidget *parent) : QWidget(parent)
>> {
>>   init();
>> }
>>
>> void imemMediaWidget::init()
>> {
>>   view.setScene(&scene);
>>     scene.setSceneRect(scene.itemsBoundingRect());
>>   view.setBackgroundBrush(QPixmap("No-Ones-Laughing-3.jpg"));
>>   view.show();
>> }
>>
>> Luc Devallonné schrieb:
>>     
>>> Strange behavior, could you post some code that demonstrates the problem ?
>>>
>>> Luc
>>>
>>> On Sun, Mar 8, 2009 at 4:14 PM, Martin Schröer <gordon at gordonswelt.de>
>>> wrote:
>>>
>>>       
>>>> Hmm ... when i try to do so ( i have some graphicsview code inside a
>>>> QWidget
>>>> class implementation), it shows the GraphicsView content outside of the
>>>> window containing the widget in a own window ... ?
>>>>
>>>> Luc Devallonné schrieb:
>>>>
>>>>         
>>>>> Martin,
>>>>>
>>>>> Actually QGraphicsView is a QWidget (QAbstractScrollArea -> QFrame ->
>>>>> QWidget), and as such can be layout as any other QWidget.
>>>>>
>>>>> Luc
>>>>>
>>>>> On Sun, Mar 8, 2009 at 3:51 PM, Martin Schröer <gordon at gordonswelt.de>
>>>>> wrote:
>>>>>
>>>>>
>>>>>           
>>>>>> Is it possible to have a QGraphicsview nested inside a QWidget, so
>>>>>> the resulting Widget could be placed, used and layouted like any other
>>>>>> widget ?
>>>>>>
>>>>>> Martin
>>>>>> _______________________________________________
>>>>>> Qt-interest mailing list
>>>>>> Qt-interest at trolltech.com
>>>>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>>>> _______________________________________________
>>>>> Qt-interest mailing list
>>>>> Qt-interest at trolltech.com
>>>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>>>>
>>>>>
>>>>>           
>>>>         
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at trolltech.com
>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>>
>>>       
>>     
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   




More information about the Qt-interest-old mailing list