Hide/Remove preview widget from QColumnView?
-
@VRonin Setting None in python for Preview Widget (equivalent of nullptr) results in crash. Added the code below. If possible, Can you please check the same in C++ and Qt? Thanks in advance.
from PyQt4 import QtCore, QtGui import os try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s try: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig) class MyModel(QtGui.QFileSystemModel): def __init__(self): super().__init__() def hasChildren(self,index): hasChildren=super().hasChildren(index) path=super().filePath(index) dirIter=QtCore.QDirIterator(path,QtCore.QDir.AllDirs|QtCore.QDir.NoDotAndDotDot|QtCore.QDir.NoSymLinks) if dirIter.hasNext(): return True else: return False return hasChildren class columnView(QtGui.QDialog): def __init__(self,parent=None): super().__init__(parent) self.ui = Ui_Dialog() self.ui.setupUi(self) self.model=MyModel() self.model.setFilter(QtCore.QDir.AllDirs|QtCore.QDir.NoDotAndDotDot|QtCore.QDir.NoSymLinks) path=os.path.expanduser("~") self.model.setRootPath(path) self.ui.columnView.setModel(self.model) self.ui.columnView.setRootIndex(self.model.index(path)) self.ui.columnView.updatePreviewWidget.connect(self.closePreview) self.show() self.ui.closePushButton.clicked.connect(self.close) def closePreview(self,index): self.ui.columnView.setPreviewWidget(None) class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName(_fromUtf8("Dialog")) Dialog.resize(596, 389) self.verticalLayout = QtGui.QVBoxLayout(Dialog) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.columnView = QtGui.QColumnView(Dialog) self.columnView.setObjectName(_fromUtf8("columnView")) self.verticalLayout.addWidget(self.columnView) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.closePushButton = QtGui.QPushButton(Dialog) self.closePushButton.setObjectName(_fromUtf8("closePushButton")) self.horizontalLayout.addWidget(self.closePushButton) self.verticalLayout.addLayout(self.horizontalLayout) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): Dialog.setWindowTitle(_translate("Dialog", "Dialog", None)) self.closePushButton.setText(_translate("Dialog", "Close", None)) if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) view = columnView() sys.exit(app.exec_())
-
Hi,
Setting a null preview widget will make it crash and that's normal. IIRC, there's usually a mention in the documentation when it's supported. In this case, the code of QColumnView doesn't show anything in that regard.
What about just hiding that preview widget ?
-
Hi,
Setting a null preview widget will make it crash and that's normal. IIRC, there's usually a mention in the documentation when it's supported. In this case, the code of QColumnView doesn't show anything in that regard.
What about just hiding that preview widget ?
@SGaist said in Hide/Remove preview widget from QColumnView?:
Setting a null preview widget will make it crash and that's normal. IIRC, there's usually a mention in the documentation
from http://doc.qt.io/qt-5/qcolumnview.html#previewWidget:
Returns the preview widget, or 0 if there is none.
I count this as a "mention"
-
Thank you all for replying. Yes looks like there's no way to do this. But when you Google around, you could see many of them find this widget annoying and wanted to turn this off. Hope Qt developers will look into this and provide an option for setVisible(False).
-
@VRonin While I concur it's mentioned in the getter, I'll understand it as when none has been set yet. The mention I was talking about should be in the getter function. Maybe an update to the doc would make the situation clearer.
As for the visibility problem, what about
myColumnCiew->previewWidget()->hide();
? -
@VRonin While I concur it's mentioned in the getter, I'll understand it as when none has been set yet. The mention I was talking about should be in the getter function. Maybe an update to the doc would make the situation clearer.
As for the visibility problem, what about
myColumnCiew->previewWidget()->hide();
?