how to combine 2D and 3D widgets

834 views
Skip to first unread message

Rodrigo Amestica

unread,
Jan 11, 2014, 6:24:09 PM1/11/14
to pyqt...@googlegroups.com

Hello,

I'm trying to display together 2 items. One is a plot with respect to time of a few scalar variables (PlotWidget). The second is a 3D axis mesh that re-orients (rotate) every time there is more data available (GLGridItem).

Short of an explicit example I came up with the code shown below.

The problem I have is that the 3D widget starts with a size of zero and, therefore, it is not visible. Instead, if immediately after instantiating the GLViewWidget then I set its minimum size (view.setMinimumSize) to some meaningful size then the widget is visible together with the 2D plot.

Why is that the layout is not 'sizing' the 3D widget automagicaly to the right size? Is it really okay to mix GL and non GL widgets?

Thanks,
 Rodrigo

from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import pyqtgraph.opengl as gl
app = QtGui.QApplication([])
w = QtGui.QWidget()
layout = QtGui.QGridLayout()
w.setLayout(layout)
plot = pg.PlotWidget()
view = gl.GLViewWidget()
#view.setMinimumSize(384,360)
xgrid = gl.GLGridItem()
view.addItem(xgrid)
layout.addWidget(plot, 0, 0)
layout.addWidget(view, 2, 0)
w.show()

Luke Campagnola

unread,
Jan 11, 2014, 8:03:41 PM1/11/14
to pyqt...@googlegroups.com
The problem here is that the PlotWidget and the GLViewWidget are competing for space in the layout, and the PlotWidget has more aggressive default settings because it inherits from QGraphicsView. To be honest, I have never really understood Qt's layout system, but there is an easy workaround if you want to force two widgets to share space equally: make their sizePolicy the same, and make them both return the same value for sizeHint:

    plot.sizeHint = view.sizeHint = lambda: pg.QtCore.QSize(100, 100)
    view.setSizePolicy(plot.sizePolicy)


Luke

Rodrigo Amestica

unread,
Jan 11, 2014, 10:56:16 PM1/11/14
to pyqt...@googlegroups.com
At Sat, 11 Jan 2014 20:03:41 -0500,
Luke Campagnola wrote:
>
> [1 <text/plain; ISO-8859-1 (7bit)>]
>
> [2 <text/html; ISO-8859-1 (quoted-printable)>]
just like that the second line did not work. Replaced sizePolicy by sizePolicy()
and now it works. Which seems to make sense after checking that sizePolicy
returns a QSizePolicy value.

The '100' values have an effect on the initial size of the frame, which means
that some logic (take into account the total number of widgets at the end) would
be needed for a more comfortable situation right after starting the application.

I really appreciate your prompt help.

Thanks,
Rodrigo

Luke Campagnola

unread,
Jan 12, 2014, 11:01:18 AM1/12/14
to pyqt...@googlegroups.com
Correct; my mistake.
 
The '100' values have an effect on the initial size of the frame, which means
that some logic (take into account the total number of widgets at the end) would
be needed for a more comfortable situation right after starting the application.

You can either provide sizeHint values that make more sense for your application, or call `w.resize(w, h)`.


Luke
 

mag...@mayah.com

unread,
Jan 19, 2018, 6:12:16 PM1/19/18
to pyqtgraph
Hey Luke, 

first of all thanks for the great package. I am working in a AI domain and plotted my 3D Latent Space embeddings with opengl and it just looks amazing. 

If you could help me out with this one problem I would be very happy:-)
I am trying to have a 3D Plot and a 2D Plot below. My 2D Plot additionally has a LinearRegionItem and updates the colors of my 3D plot depending on the region specified. 
I got this working for two 2D plots^^. Do you think this works out for 3D and 2D somehow, and if not would it be possible to add to the 3D plot a input field where I could specify the threshold value for the colors on my 3D plot? 

Best regards,
Magnus
Reply all
Reply to author
Forward
0 new messages