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. How to remove the area on the left of QTreeView first column?
Forum Updated to NodeBB v4.3 + New Features

How to remove the area on the left of QTreeView first column?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 826 Views 1 Watching
  • 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.
  • L Offline
    L Offline
    Lailla
    wrote on last edited by Lailla
    #1

    How can I remove this area seen inside the red rectangle?

    QtWidgetsApplication1_MYW4ZZBT0B.png

    Things I have tried:

    • setIndentation(0);
    • setRootIsDecorated(false);
    • overriding drawBranches
    • Styling it with QTreeView::branch and setting width: 0px and also background-color: transparent;

    I'm using Qt 6.6.
    I dont know what this area from, as indentation is set to 0 what else could be this?

    Setting the first column hidden also hides this area but i would need to use everything like column()+1 it would be a mess.

    class MyTreeView : public QTreeView
    {
    public:
        MyTreeView(QWidget* parent = nullptr) : QTreeView(parent)
        {
    	    QStandardItemModel*	model = new QStandardItemModel(this);
    	    setModel(model);
    	    setObjectName("treeView");
            setIndentation(0);
            setRootIsDecorated(false);
      
            for (int i =0; i< 2; i++)
            {
                QList<QStandardItem*> row;
                for (int j = 0; j < 2; j++)
                {
        		    row.append(new QStandardItem(QString::number(j)));
                }
                model->appendRow(row);
            }
    
            setStyleSheet(R"(
    QTreeView 
    { 
        outline: 0px;
    }
    
    QTreeView::item
    {
    	min-height: 32px;
    	border: 2px solid rgba(222, 222, 222, 255);
    	border-radius: 12px;
    	padding-left: 10px;
    
    }
    
    QTreeView::item:hover 
    {
    	background-color: rgba(177, 177, 177, 255);
    	border: 2px solid rgba(177, 177, 177, 255);
    }
    
    QTreeView::item:selected 
    {
    	background-color: rgba(157, 157, 157, 255);
    	border: 2px solid rgba(177, 177, 177, 255);
    }
    
    QTreeView::branch 
    {
        background-color: transparent;
    	border: 0px;
    	width: 0px;
    }
            )");
        }
    
    	void drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const override
    	{
    		//QTreeView::drawBranches(painter, rect, index);
    	}
    
    	void drawRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override
    	{
    		QStyleOptionViewItem opt = option;
    
            if (index.column() == 0)
                opt.rect.moveLeft(-10);
    		QTreeView::drawRow(painter, opt, index);
    	}
    
    };
    
    
    int main(int argc, char* argv[])
    {
        QApplication a(argc, argv);
    
        QWidget w;
    	QHBoxLayout layout(&w);
        MyTreeView myTreeview;
    	layout.addWidget(&myTreeview);
    	w.show();
        return a.exec();
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Use another style. The windows11 style is using this as the indicator for the current row

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • L Offline
        L Offline
        Lailla
        wrote on last edited by Lailla
        #3

        @Christian-Ehrlicher I'm testing this on Windows 10, do you know where in the source this indicator is drawn?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          In the windows 11 style code.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Lailla
            wrote on last edited by
            #5

            In the windows 11 style code.

            How helpful

            Christian EhrlicherC 1 Reply Last reply
            1
            • L Lailla

              In the windows 11 style code.

              How helpful

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Lailla said in How to remove the area on the left of QTreeView first column?:

              How helpful

              What's wrong?
              windows11 style is in qwindows11style.cpp and then look for itemview. You will find two places (PE_PanelItemViewRow and CE_ItemViewItem) - somewhere there it is drawn.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • I Offline
                I Offline
                IgKh
                wrote on last edited by IgKh
                #7

                AFAIK the Windows 11 style (AKA "modern windows style") only works on Windows 11 proper - and then only starting Qt 6.7. Qt apps running on Windows 10 still use the older Qt Windows Vista style. However this particular bit might be the same in both, not sure, never could read QStyle code all that well.

                @Lailla to see if the style does matter, try running your app with different styles by running the EXE with a -style flag. You can try the Fusion and windows (Windows 9.x) styles, they are built-in.

                Christian EhrlicherC 1 Reply Last reply
                0
                • I IgKh

                  AFAIK the Windows 11 style (AKA "modern windows style") only works on Windows 11 proper - and then only starting Qt 6.7. Qt apps running on Windows 10 still use the older Qt Windows Vista style. However this particular bit might be the same in both, not sure, never could read QStyle code all that well.

                  @Lailla to see if the style does matter, try running your app with different styles by running the EXE with a -style flag. You can try the Fusion and windows (Windows 9.x) styles, they are built-in.

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @IgKh said in How to remove the area on the left of QTreeView first column?:

                  nd then only starting Qt 6.7. Qt apps running on Windows 10 still use the older Qt Windows Vista style. However this particular bit might be the same in both, not sure, never could read QStyle code all that well.

                  No

                  You can use the windows11 style on windows 10 without any problems. But you have to set it explicitly.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  I 1 Reply Last reply
                  1
                  • L Offline
                    L Offline
                    Lailla
                    wrote on last edited by Lailla
                    #9

                    @IgKh i tried the styles you have mentioned, on all of them this thing is drawn.

                    windows11 style is in qwindows11style.cpp and then look for itemview. You will find two places (PE_PanelItemViewRow and CE_ItemViewItem) - somewhere there it is drawn.

                    I have found where " the indicator for the current row" is drawn.
                    qtreeview.cpp

                    style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this);
                    

                    I have tested commenting this line and recompiling and its gone.

                    I'm not relying on any built-in/default style(s).
                    I'll leave the topic open to see if someone else knows another way to hide/disable it.

                    Christian EhrlicherC Pl45m4P 2 Replies Last reply
                    0
                    • L Lailla

                      @IgKh i tried the styles you have mentioned, on all of them this thing is drawn.

                      windows11 style is in qwindows11style.cpp and then look for itemview. You will find two places (PE_PanelItemViewRow and CE_ItemViewItem) - somewhere there it is drawn.

                      I have found where " the indicator for the current row" is drawn.
                      qtreeview.cpp

                      style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this);
                      

                      I have tested commenting this line and recompiling and its gone.

                      I'm not relying on any built-in/default style(s).
                      I'll leave the topic open to see if someone else knows another way to hide/disable it.

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Lailla said in How to remove the area on the left of QTreeView first column?:

                      I'll leave the topic open to see if someone else knows another way to hide/disable it.

                      As you already wrote it's this line - so how should it be disabled by any other way than removing this line or using another style?? there is no condition for this line so there is no other way.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      3
                      • L Lailla

                        @IgKh i tried the styles you have mentioned, on all of them this thing is drawn.

                        windows11 style is in qwindows11style.cpp and then look for itemview. You will find two places (PE_PanelItemViewRow and CE_ItemViewItem) - somewhere there it is drawn.

                        I have found where " the indicator for the current row" is drawn.
                        qtreeview.cpp

                        style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this);
                        

                        I have tested commenting this line and recompiling and its gone.

                        I'm not relying on any built-in/default style(s).
                        I'll leave the topic open to see if someone else knows another way to hide/disable it.

                        Pl45m4P Offline
                        Pl45m4P Offline
                        Pl45m4
                        wrote on last edited by
                        #11

                        @Lailla said in How to remove the area on the left of QTreeView first column?:

                        I'm not relying on any built-in/default style(s).
                        I'll leave the topic open to see if someone else knows another way to hide/disable it.

                        Another way would be your own custom QStyle... then it can be switch at run time...
                        (before you start modifying your Qt source build)

                        Maybe at some point you might find this indicator thing helpful again :)
                        Or your software is linked by some customer/user with another default version of Qt... then it looks like before again
                        (unless you have Qt statically linked to your app)


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          @IgKh said in How to remove the area on the left of QTreeView first column?:

                          nd then only starting Qt 6.7. Qt apps running on Windows 10 still use the older Qt Windows Vista style. However this particular bit might be the same in both, not sure, never could read QStyle code all that well.

                          No

                          You can use the windows11 style on windows 10 without any problems. But you have to set it explicitly.

                          I Offline
                          I Offline
                          IgKh
                          wrote on last edited by
                          #12

                          @Christian-Ehrlicher said in How to remove the area on the left of QTreeView first column?:

                          No

                          You can use the windows11 style on windows 10 without any problems. But you have to set it explicitly.

                          Indeed this is true now! In my defense, I'll say that this is the case only from 6.8.1, was not mentioned in the changelog for that version and the in-code documentation still claims it doesn't work on Windows 10.

                          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