Can't get widget expanding that has a QGraphicsView as parent



  • Hi,

    i cant get a Widget expand horizontally that has a QGraphicsView as parent.
    The widget should take the whole horizontal space that is available inside the QGraphicsView.
    I tried like 1000 combinations of Settings with Layout, without Layout, with different child Widgets and so on.
    (you can download the whole project-folder here: http://ubuntuone.com/0HPWnb4YyLyHDe2nWBtNbb )

    Source:
    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    ui->view->setScene(&scene);
    ui->view->show();
    scene.setBackgroundBrush(Qt::DiagCrossPattern);
    
    myWidget = new QWidget(ui->view,Qt::Widget);
    myWidget->setAutoFillBackground(true);
    myWidget->setMinimumSize(64,32);
    myWidget->setMaximumSize(512,128);
    myWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    
    myTextEdit = new QTextEdit(myWidget);
    myTextEdit->setMaximumSize(64,16);
    myTextEdit->setMaximumSize(512,64);
    myTextEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    
    myButton = new QPushButton("a Button", myWidget);
    
    myLayout = new QVBoxLayout;
    myLayout->addWidget(myTextEdit);
    myLayout->addWidget(myButton);
    
    myWidget->setLayout(myLayout);
    

    }@
    Header:
    @namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    QGraphicsScene scene;

    QSpinBox* mySpinBox;
    QTextEdit* myTextEdit;
    QDockWidget* myDock;
    QWidget* myWidget;
    QVBoxLayout* myLayout;
    QPushButton* myButton;
    

    public slots:
    void btn_hide(void);

    private:
    Ui::MainWindow *ui;
    };@


  • Moderators

    Using setMaximumSize() on any widget will prevent it from expanding beyond that size.



  • Hi Artemus,

    set layout to Graphicsview as below
    @
    QVBoxLayout *vlay = new QVBoxLayout();
    vlay->addWidget(myWidget);
    ui->view->setLayout(vlay);
    @

    [Edit: Please wrap code in @ tags; mlong]


Log in to reply
 

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