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't get widget expanding that has a QGraphicsView as parent
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.8k 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.
  • A Offline
    A Offline
    Artemus
    wrote on last edited by
    #1

    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;
    };@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

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

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Atul Patil
        wrote on last edited by
        #3

        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]

        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