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. QTreeView add widget below/around the widget from within QTreeView widget...
Forum Updated to NodeBB v4.3 + New Features

QTreeView add widget below/around the widget from within QTreeView widget...

Scheduled Pinned Locked Moved Solved General and Desktop
qtreeviewqwidget
12 Posts 2 Posters 2.7k 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.
  • SGaistS SGaist

    Hi,

    Why not implement a subclass of QWidget that will contain your QTreeView and whatever other widgets you want around ?

    D Offline
    D Offline
    Dariusz
    wrote on last edited by
    #3

    @SGaist Because then user cant do widget->setModel() without me re-implementing all needed QTreeView functions.

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

      You can provide that method, or you can follow the same logic as for example QComboBox uses and make some internal parts available.

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

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Dariusz
        wrote on last edited by
        #5

        Hmm I would prefer avoiding hand providing all methods I need to of QTreeView - like a wrapper.
        Will read in to QComboBox.
        So far I tried also adding a layout QTreeView which somehow worked, but the problem is that layout and its children are located over the tree view and not above/below/etc

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

          What design do you have in mind ?

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

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

            To start with I was hoping to provide a "external" drop area that would drop items in specific place in view if dropped on to. Right now I've used resizeEvent to move a QLabel styled as drop area around qTreeView, but I can only move it over the treeView. I want to squeeze tree view to place the label(drop area) in different places. I also would like to tinker with other ideas but so far this is the main one.

            resizeEvent()
                    _dropArea->move(1, viewport()->height() + 2);
                    _dropArea->setFixedWidth(width() - 2);
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              Then you should really compose a new widget. Part of your description makes me think of QMainWindow's implementation with its QDockWidget areas.

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

              1 Reply Last reply
              1
              • D Offline
                D Offline
                Dariusz
                wrote on last edited by
                #9

                Is there not a simple way to force redraw of widget ? Like giving it different margins/etc? I tried with geometry but thats being overridden by layout. SetViewportMargins() seems to be overwritten by scrollArea I think.

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

                  You can re-implement QTreeView's paintEvent but still, it doesn't change the fact that you are trying to compose a complex widget within an already complex widget.

                  You seem to want to avoid providing a relatively simple API while at the same time trying to implement a very complex workaround. As suggested before, you can use the QComboBox model which allows to access some internal parts (for example through view while providing a simple API like setModel or setView.

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

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Dariusz
                    wrote on last edited by Dariusz
                    #11

                    Well its more like case study to see how far widgets can be pushed/break apart. Ill try paint event next. But never did any extensive widget editing there so should be interesting. Its kinda... common, say I want to make a set, QLineEdit+QPushButton, I would just want to expose qlineedit and q pushbutton should do all the magic atomatically the second lineEdit has been made. So I can see more and more use cases for this idea. I don't think is particularly good having to make QWidget,QLayout, QlineEdit and QPushButton if I could just make QLineEdit + QPushButton.

                    Also in qt examples they show also some simmilar systems where 1 widget is aided by another one but only the main widget is being exposed
                    http://doc.qt.io/qt-5/qtwidgets-itemviews-frozencolumn-example.html
                    Also in here >
                    http://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html
                    Too bad that setting viewport margins in treeView like in QPlainTextEdit editor does not work :-(
                    Regards
                    Dariusz

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Dariusz
                      wrote on last edited by Dariusz
                      #12

                      Ok so after LOTS of fighting with QTreeView... I started looking at viewport() and wuaila!

                      void myTree::resizeEvent(QResizeEvent *event) {
                          QAbstractItemView::resizeEvent(event);
                          b->setFixedSize(event->size().width(), 25);
                          b->move(0,height()-25);
                          viewport()->setMaximumHeight(height() - 50);
                      };
                      

                      Now my viewport gets painted exactly where I want it to, and the extra buttons can be placed in area where I want it to (b is the button) + its all nice all in one widget. I can expose needed controls for b as pert spec but drawing is as it should. Yay!

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved