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. Hide/Remove preview widget from QColumnView?

Hide/Remove preview widget from QColumnView?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 2.2k 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.
  • R Offline
    R Offline
    rtfa
    wrote on last edited by
    #1

    Is there any way to do this? Looks like this functionality is not provided in QColumnView. Not everybody would like to have previews and it's not suitable for all cases.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Not sure but I would try:
      connect(columnView,&QColumnView::updatePreviewWidget,[=]()->void{columnView->setPreviewWidget(nullptr);});

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rtfa
        wrote on last edited by
        #3

        @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_())
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          VRoninV 1 Reply Last reply
          0
          • R Offline
            R Offline
            rtfa
            wrote on last edited by
            #5

            @SGaist There's no option to provided to hide the previewWidget. Even if no widget is set, the column gets created and displays nothing.

            1 Reply Last reply
            0
            • SGaistS SGaist

              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 ?

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @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"

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Devopia53
                wrote on last edited by
                #7

                There is no way to remove preview column even if no widget was set.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rtfa
                  wrote on last edited by
                  #8

                  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).

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @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(); ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    R 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      @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(); ?

                      R Offline
                      R Offline
                      rtfa
                      wrote on last edited by
                      #10

                      @SGaist When we hide() the preview widget, it will hide the widgets if something is set as preview widget. It's not preventing the columview from creating the extra column.

                      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