mxcube / mxcubeqt

Qt Front-end of MXCuBE
http://mxcube.github.io/mxcube/
GNU Lesser General Public License v3.0
14 stars 34 forks source link

Qt Front-end of MXCuBE - designer - Splitters : can't add to GUI #396

Closed natxo14 closed 4 years ago

natxo14 commented 4 years ago

Trying to use/add vertical or horizontal splitters to a GUI with qt MxCUBE version, I found some issues:

Splitter constructor was called with too much parameters (error raised when trying to create a splitter object), so in gui/utils/GUIDisplay.py , had to change from

def get_horizontal_splitter(*args, **kwargs):
     """Horizontal splitter"""
     return QtImport.QSplitter(QtImport.Qt.Horizontal, *args)

to

def get_horizontal_splitter(*args, **kwargs):
     h_splitter = QtImport.QSplitter(QtImport.Qt.Horizontal, args[0])
     h_splitter.setObjectName(args[1])
     return h_splitter

and also, as a splitter has no layout, in def add_widget(self, child, parent): function had to add

elif isinstance(parent_item,QtImport.QSplitter):
    parent_item.addWidget(new_item)

after the if isinstance(parent, TabCfg): statement.

Now no errors are raised, but when executing the gui file, nothing included on the splitter widget is displayed.

Does anyone know about what could be failing or missing to integrate splitters correctly on a GUI?? Thanks!

IvarsKarpics commented 4 years ago

Hi @natxo14 . I will have a look at the issue. Are you using PyQt4 or PyQt5 ?

natxo14 commented 4 years ago

Hi @IvarsKarpics , thanks for your reply. I'm on PyQt5. If this helps: On gui/utils/GUIDisplay.py file some wrappers for common Qt widgets ( Spacer, CustomFrame, CustomGroupBox ... ) are created, but QSplitter is used directly on the code. Besides on the WindowDisplayWidget.add_item(self, item_cfg, parent): function, the code splits in conditionals according to the item_type, and for the case of splitters ( vertical or horizontal ), there's no instruction at all:

elif item_type == "vsplitter" or type == "hsplitter":
                pass

If you find out what's missing and explaining it to me is going to cost you less than coding it, I'd be pleased to fix it. Thanks!

IvarsKarpics commented 4 years ago

Hi @natxo14 . We are using PyQt4 and PyQt5 behaves sometimes different and is not tested enough. So, its not a wonder that some bugs appear. I have a ubuntu virtual machine with python3 and PyQt5. I will try to fix it. Meanwhile, of course you can open PR with a solution.

vrey01 commented 4 years ago

Hi @natxo14

Yes. I looked at it. It seems that the Splitter classes have never been used in "mxcube" (at least in Qt4/Qt5) but "nearly" everything is ready for them.

Other than the modified calls to the constructor that you have already fixed, there is the "addWidget" call missing for children of the QSplitter. The reason is that QSplitter is a container but has no layout manager, addWidget must be called directly on the splitter class.

In Qt4_GUIDisplay.py file:

in method make_item() at the end of the loop through children, there is the block that calls addWidget on layouts. It should be modified to something like:

if layout is not None: [......] elif isinstance(parent,QSplitter): self.preview_items.append(new_item) parent.addWidget(new_item)

See if that solves your problem. Probably some customization of the splitter is still needed in the horizontalSplitter / verticalSplitter splitter creation methods.

Have fun !

marcus-oscarsson commented 4 years ago

Whoo, your a star @vrey01 !

IvarsKarpics commented 4 years ago

Thanks @vrey01 . PR with solution is in #397

IvarsKarpics commented 4 years ago

Solved with #397