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. QComboboox with treeview and custom event handler

QComboboox with treeview and custom event handler

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 705 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.
  • A Offline
    A Offline
    arsinte_andrei
    wrote on last edited by
    #1

    this is what I have so far
    @#ifndef ATPTREECOMBOBOX_H
    #define ATPTREECOMBOBOX_H

    #include "atpTreeComboBoxView.h"
    #include <QApplication>
    #include <QtGui>
    #include <QTreeView>
    #include <QHeaderView>
    #include <QComboBox>

    class atpTreeComboBox : public QComboBox {
    public:
    atpTreeComboBox(QWidget* parent = 0) : QComboBox(parent), skipNextHide(false) {
    //atpTreeComboBoxView *atpTreeView = new atpTreeComboBoxView(this);
    setView(atpTreeView);
    view()->viewport()->installEventFilter(this);
    }

    bool eventFilter(QObject* object, QEvent* event) {
    if (event->type() == QEvent::MouseButtonPress && object == view()->viewport()) {
    QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
    QModelIndex index = view()->indexAt(mouseEvent->pos());
    if (!view()->visualRect(index).contains(mouseEvent->pos()))
    skipNextHide = true;
    }
    return false;
    }

    virtual void showPopup() {
    setMaxVisibleItems(10);
    setRootModelIndex(QModelIndex());
    QComboBox::showPopup();
    }

    virtual void hidePopup() {
    //setRootModelIndex(view()->currentIndex().parent());
    //setCurrentIndex(view()->currentIndex().row());
    if (skipNextHide)
    skipNextHide = false;
    else
    QComboBox::hidePopup();
    }

    private:
    bool skipNextHide;
    };

    #endif // ATPTREECOMBOBOX_H
    @

    but I wish to be able to add the view not in the class because when I add a model to it it will not hide the columns
    so i have a QStandardItemModel with 3 columns and i wish to display only one.
    on the qtreeview is displaying corecly
    but when i set the same view to my atpCombobox it will not display corecly and also it won't take in account the event handler.

    I wish to be able to send the view as an argument and to keep event filter and show and hide popup working
    even if i set a new view (so without set it up in the class - the class to receive the view as an argument)
    @
    QStandardItemModel *m = new QStandardItemModel(this);
    m->setColumnCount(3);
    m->setHeaderData(0, Qt::Horizontal,"Name");
    m->setHeaderData(1, Qt::Horizontal,"ID");
    m->setHeaderData(2, Qt::Horizontal,"Parent");
    QtreeView comboView = new QTreeView(this);

    mycombo = new atpTreeComboBox(this, comboView);
    mycombo->setModel(m);
    mycombo->setView(comboView );
    mycombo->setGeometry(90,100,330,22);
    mycombo->show();
    mycombo->setMaxVisibleItems(10);
    @

    any help will apreciate a lot

    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