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. Problem mixing QGraphicsItem and QGraphicsProxyWidget
Forum Updated to NodeBB v4.3 + New Features

Problem mixing QGraphicsItem and QGraphicsProxyWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 346 Views
  • 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.
  • X Offline
    X Offline
    XavierLL
    wrote on last edited by XavierLL
    #1

    Hi,

    I have a simple setup with a graphicsscene where I mix QGraphicsItem and QGraphicsProxyWidget.

    When I mix two of them as in this simple example ( just a basic MainWindow project with a simple scene and two panel widgets). The QGraphicsItem (a rect in this case) is drawing outside of the graphics view when you resize the mainwindow.

    This is the code to reproduce the error.

    MainWindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    protected slots:
    
    private:
    };
    
    #endif // MAINWINDOW_H
    

    MainWindow.cpp

    #include "mainwindow.h"
    
    #include <QVBoxLayout>
    #include <QGraphicsScene>
    #include <QGraphicsView>
    #include <QGraphicsProxyWidget>
    #include <QLabel>
    #include <QPushButton>
    #include <QBrush>
    
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent)
    {
        QWidget *centralWdg = new QWidget();
        setCentralWidget(centralWdg);
    
    
        QHBoxLayout *hlayout = new QHBoxLayout();
        QWidget *leftWdg = new QWidget(this);
        leftWdg->setMinimumWidth(200);
    
        QWidget *rightWdg = new QWidget(this);
        rightWdg->setMinimumWidth(200);
    
    
        QGraphicsScene *gs = new QGraphicsScene();
    
        QGraphicsView *gv = new QGraphicsView(gs, this);
        gv->setMaximumWidth(180);
    
        gs->addWidget(new QLabel("Label"));
    
        hlayout->addWidget(leftWdg);
        hlayout->addWidget(gv);
        gv->setBackgroundBrush(QBrush(Qt::yellow, Qt::DiagCrossPattern));
        hlayout->addWidget(rightWdg);
    
        QGraphicsItem *r = gs->addRect(50,50,150,50, QColor(Qt::red), QColor(Qt::blue));
        r->setFlags(QGraphicsItem::GraphicsItemFlag::ItemIsMovable);
    
        centralWdg->setLayout(hlayout);
    }
    
    MainWindow::~MainWindow()
    {
    
    }
    

    main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    

    And this is the rendering i obtain:

    https://s13.postimg.io/734u4kmpz/rendering_Problem.png

    Not sure if I am missing something or is it a bug or limitation in QT QGraphicsView framework.

    Running with Qt 5.7.0 and windows 8.1

    thanks,

    Xllr

    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