Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertical scroll bar of panels is not proportional to the size of the content #21689

Closed
dan123456-eng opened this issue Jan 10, 2024 · 11 comments
Closed

Comments

@dan123456-eng
Copy link
Contributor

dan123456-eng commented Jan 10, 2024

Problem Description

I noticed that in the Help panel and the IPython Console panel the vertical scrollbar works correctly (From what I understand it uses QWebEngineView).

Small vertical scrollbar

test1
test2
test5

Correctly sized vertical scrollbar

test3
test4

What steps reproduce the problem?

  1. To reproduce the problem, simply move the lower panel size control bar so that the vertical bar appears.

Versions

Spyder version: 5.5.0
Python version: Python 3.12
Qt version: n/a
PyQt version: PyQt5= 5.15.10
Operating System name/version: Windows10 and Ubuntu

@dan123456-eng
Copy link
Contributor Author

dan123456-eng commented Jan 10, 2024

In the first image I used a test called MyTreeview. The vertical scrollbar works correctly sized for testing outside of Spyder. But when I add a vertical scrollbar to a Spyder panel it works strangely (small), a horizontal scrollbar works correctly.

On the Spyder

class PyMRWorkspacePluginWidget(PluginMainWidget):
    """PyMR workspace main widget."""

    ENABLE_SPINNER = True

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        test = MyTreeView()
        # Layout principal
        lay = QtWidgets.QVBoxLayout(self)
        lay.addWidget(test)

Testing outside the Spyder

from PyQt5 import QtWidgets, QtGui, QtCore
from spyder.api.widgets.main_widget import PluginMainWidget

class MyTreeView(PluginMainWidget):
    def __init__(self, *args, **kwargs):
        super().__init__('name', 'plugin')
        
        model = QtGui.QStandardItemModel(self)

        
        numofItems = 30
        for x in range(numofItems):
            item = QtGui.QStandardItem('Test {}'.format(x+1))
            item.setCheckable(True)
            item.setCheckState(QtCore.Qt.Checked)  # Defina para QtCore.Qt.Unchecked se desejar desmarcar por padrão
            model.appendRow(item)


        treeView = QtWidgets.QTreeView(self)
        treeView.setModel(model)
        #treeView.setHeaderHidden(True)  # Oculta o cabeçalho da QTreeView

        
        v_scrollbar = treeView.verticalScrollBar()
        v_scrollbar.setMinimumWidth(15)  # Ajusta a largura da barra de rolagem conforme necessário
        v_scrollbar.setStyleSheet("QScrollBar:vertical { width: 15px; }")

     
        lay = QtWidgets.QVBoxLayout(self)
        lay.addWidget(treeView)
        self.setLayout(lay)


app = QtWidgets.QApplication([])
window = MyTreeView()
window.show()
app.exec_()

@dan123456-eng
Copy link
Contributor Author

dan123456-eng commented Jan 17, 2024

I used the test below and the vertical scrollbar works correctly. I'm checking the source of the problem. Do you know of anything that could direct a path?

`def run_test(): # Third party imports from qtpy.QtWidgets import QVBoxLayout, QTableWidget, QMainWindow, QTreeView from qtpy.QtCore import QDir from PyQt5 import QtWidgets

# Local imports
from spyder.utils.qthelpers import qapplication
from spyder.api.widgets.main_widget import PluginMainWidget
from spyder.utils.stylesheet import APP_STYLESHEET

app = qapplication()
main = QMainWindow()

widget = PluginMainWidget('test', main)
widget.get_title = lambda x=None: 'Test title'
widget._setup()

tree_view = QTreeView()
file_system_model = QtWidgets.QFileSystemModel()
file_system_model.setRootPath(QDir.rootPath())  # Defina o diretório raiz conforme necessário
tree_view.setModel(file_system_model)

table_widget = QTableWidget()

# Adicionar ambos os widgets ao layout
layout = QVBoxLayout()
layout.addWidget(tree_view)
layout.addWidget(table_widget)

widget.setLayout(layout)
widget.start_spinner()

dock, location = widget.create_dockwidget(main)
main.addDockWidget(location, dock)

# Configurar a largura mínima da dock para garantir que a QTreeView seja visível
dock.setMinimumWidth(200)
main.setStyleSheet(str(APP_STYLESHEET))
main.show()
app.exec_()

if name == 'main': run_test()`

TEST

@ccordoba12
Copy link
Member

Hey @dan123456-eng, thanks for reporting. Did you manage to solve this problem? Or did you close the issue by accident?

If that was the case, then I think perhaps it occurs because the QTreeView widgets you're creating have no parent.

@dan123456-eng dan123456-eng reopened this Jan 17, 2024
@dan123456-eng
Copy link
Contributor Author

@ccordoba12 Sorry it was an accident.

@ccordoba12
Copy link
Member

ccordoba12 commented Jan 17, 2024

Ok, please change these lines in your code example above to be

tree_view = QTreeView(parent=widget)

...

table_widget = QTableWidget(parent=widget)

I think that should solve your problem.

@dan123456-eng
Copy link
Contributor Author

dan123456-eng commented Jan 18, 2024

The vertical scroll bar for the correct code is correct, the code below is not. When used outside of Spyder it works correctly, when used in class PyMRWorkspacePluginWidget(PluginMainWidget): the scroll bar becomes small.

In the first image I used a test called MyTreeview. The vertical scrollbar works correctly sized for testing outside of Spyder. But when I add a vertical scrollbar to a Spyder panel it works strangely (small), a horizontal scrollbar works correctly.

On the Spyder

class PyMRWorkspacePluginWidget(PluginMainWidget):
    """PyMR workspace main widget."""

    ENABLE_SPINNER = True

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        test = MyTreeView()
        # Layout principal
        lay = QtWidgets.QVBoxLayout(self)
        lay.addWidget(test)

Testing outside the Spyder

from PyQt5 import QtWidgets, QtGui, QtCore
from spyder.api.widgets.main_widget import PluginMainWidget

class MyTreeView(PluginMainWidget):
    def __init__(self, *args, **kwargs):
        super().__init__('name', 'plugin')
        
        model = QtGui.QStandardItemModel(self)

        
        numofItems = 30
        for x in range(numofItems):
            item = QtGui.QStandardItem('Test {}'.format(x+1))
            item.setCheckable(True)
            item.setCheckState(QtCore.Qt.Checked)  # Defina para QtCore.Qt.Unchecked se desejar desmarcar por padrão
            model.appendRow(item)


        treeView = QtWidgets.QTreeView(self)
        treeView.setModel(model)
        #treeView.setHeaderHidden(True)  # Oculta o cabeçalho da QTreeView

        
        v_scrollbar = treeView.verticalScrollBar()
        v_scrollbar.setMinimumWidth(15)  # Ajusta a largura da barra de rolagem conforme necessário
        v_scrollbar.setStyleSheet("QScrollBar:vertical { width: 15px; }")

     
        lay = QtWidgets.QVBoxLayout(self)
        lay.addWidget(treeView)
        self.setLayout(lay)


app = QtWidgets.QApplication([])
window = MyTreeView()
window.show()
app.exec_()

@ccordoba12
Copy link
Member

ccordoba12 commented Jan 19, 2024

I don't understand your code very well. Why does MyTreeView inherit from PluginMainWidget and not from QWidget? Or even better, from QTreeView directly?

I think it doesn't need to inherit from PluginMainWidget if you plan to use it as part of of a Spyder plugin because in that case you'll have a PluginMainWidget (i.e. PyMRWorkspacePluginWidget) that will include another PluginMainWidget (i.e. MyTreeView) inside it, and that's not how our API is designed to work.

@dan123456-eng
Copy link
Contributor Author

dan123456-eng commented Jan 20, 2024

In my code I use either Qtreeview or ProjectExplorerTreeWidget (which consists of ProjectExplorerTreeWidget - FilteredDirView- DirView- DirView(QTreeView, SpyderWidgetMixin)). Up to this point everything is correct. But when I implement my file tree in the PyMRWorkspacePluginWidge class inherited from PluginMainWidget the problem occurs.

@dan123456-eng
Copy link
Contributor Author

Hello @ccordoba12. We found out why the bug occurred. We were using custom styling in our plugins that caused this change in our implementation. Thank you for your help and as soon as I can I will contribute more.

@ccordoba12
Copy link
Member

I'm glad you were able to find the cause of this problem and thanks for letting us know about it.

@dan123456-eng
Copy link
Contributor Author

dan123456-eng commented Jan 30, 2024

Thank you for your attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants