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 hide that "1" category?
QtWS25 Last Chance

QTreeView hide that "1" category?

Scheduled Pinned Locked Moved General and Desktop
20 Posts 4 Posters 17.3k 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.
  • K Offline
    K Offline
    kamac
    wrote on last edited by
    #1

    I'd like to hide that gray rectangle with "1" in it.. Is it possible?

    It's seen here,
    http://qt-project.org/doc/qt-4.8/images/selection2.png

    Just above "America".

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      You can use "setHeaderHidden(true)":http://qt-project.org/doc/qt-5.0/qtwidgets/qtreeview.html#headerHidden-prop;

      @treeView->setHeaderHidden(true);@

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kamac
        wrote on last edited by
        #3

        Thanks a bunch.
        Also, another question: Can I have different context menus for different items within TreeView?
        I'd like to decide what options to display basing on item icon path.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alexisdm
          wrote on last edited by
          #4

          When you create a custom context menu, with either the customContextMenuRequested() signal, or a redefinition of the virtual function contextMenuEvent() of your view (see "contextMenuPolicy":http://qt-project.org/doc/qt-4.8/qwidget.html#contextMenuPolicy-prop), you can get the item under the mouse with "QAbstractItemView::indexAt()":http://qt-project.org/doc/qt-4.8/qabstractitemview.html#indexAt and populate your menu accordingly.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Note that a well-behaved model would return actually useful data for the headers. So, instead of 1 it would display a useful name for the column.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kamac
              wrote on last edited by
              #6

              bq. Note that a well-behaved model would return actually useful data for the headers. So, instead of 1 it would display a useful name for the column.

              Yes althrough I don't need or want headers this time, for this application.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kamac
                wrote on last edited by
                #7

                Uh, and one more question.

                If I want to programatically add tab widget, that contains a web view, do I have to create a new class that inherits from QTabWidget? (So that I can place widgets inside QTabWidget)

                I haven't seen anything like myTab->addWidget.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alexisdm
                  wrote on last edited by
                  #8

                  QTabWidget::addTab already allows that without subclassing.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kamac
                    wrote on last edited by
                    #9

                    Eeh. Another question. It's so hard (if not impossible) to find answers for such 'easy' things.
                    Can I somehow prevent renaming tree nodes on double click that are inside QTreeView?

                    Cheers.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      alexisdm
                      wrote on last edited by
                      #10

                      You can either disable edit triggers for the whole view with:
                      @theView−>setEditTriggers(QAbstractItemView::NoEditTriggers);@

                      or make that the set of flags returned by the model's QAbstractItemModel::flags() function doesn't include Qt::ItemIsEditable for the non-editable items or use QStandardItem::setEditable(false) if the model is a QStandardItemModel.

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kamac
                        wrote on last edited by
                        #11

                        Thanks, also, is there some way to start renaming a TreeView item?
                        Something like myQStandardItem->startRenaming();

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          alexisdm
                          wrote on last edited by
                          #12

                          You have to call the view's "edit()":http://qt-project.org/doc/qt-4.8/qabstractitemview.html#edit function with the model index to edit (myQStandardItem->index()).

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            kamac
                            wrote on last edited by
                            #13

                            Another question. I've got this:
                            @
                            QModelIndex m = projectView->indexAt(p);
                            QString icn = m.data(Qt::DisplayRole).toString();
                            QMessageBox::warning(0,"!",icn);
                            @
                            But that displays name of that index (for example, someItemAtTreeView), and I want to get that item's icon instead.
                            I've tried Qt::DecorationRole, but I couldn't get it to return me a QIcon or QPixmap..

                            Edit: please use @ tags around code sections; Andre

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              andre
                              wrote on last edited by
                              #14

                              Why are you converting to a string, if what you are after is an image? I would convert to a QImage or a QPixmap...

                              And yes, you do need to use the DecorationRole.

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                kamac
                                wrote on last edited by
                                #15

                                Could you give me an example?

                                bq. Why are you converting to a string, if what you are after is an image?

                                That was an example of what works for me, though, I don't know how to change it so I get QIcon.
                                If I try:

                                QIcon icn = m.data(Qt::DecorationRole);

                                It is unable to convert it into QIcon. Hmmph. If I do: m.data(Qt::DecorationRole).toString() it's always an empty string.

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  andre
                                  wrote on last edited by
                                  #16

                                  Well, that is because it probably isn't a QIcon. Converting to a string really isn't going to help you. Did you try converting to a QImage or a QPixmap using QVariant::toImage() or QVariant::toPixmap?

                                  1 Reply Last reply
                                  0
                                  • K Offline
                                    K Offline
                                    kamac
                                    wrote on last edited by
                                    #17

                                    Uh, I don't have these functions in QVariant. Also, class reference doesn't seem to introduce them either.

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      alexisdm
                                      wrote on last edited by
                                      #18

                                      For these types, you might have to use QVariant::value<QPixmap>() / QVariant::value<QIcon>().

                                      You could check what type is actually stored with QVariant::typeName().

                                      1 Reply Last reply
                                      0
                                      • K Offline
                                        K Offline
                                        kamac
                                        wrote on last edited by
                                        #19

                                        Done.
                                        Now, is there a way to dected whether user stopped editing QTreeView item's name? (As I've forced QAbstractItemView::edit() before, now I'd like to detect when editing stops)

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          alexisdm
                                          wrote on last edited by
                                          #20

                                          If you don't set a delegate, the model is updated when the editor widget is closed, so, you can catch the change with the model's dataChanged() signal.

                                          If you want to see both the new and old data, you need to either derive the model, to override QAbstractItemModel::setData, or install a delegate, whose QAbstractItemDelegate::setModelData() function will be called at the end of editing.

                                          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