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. PushButton at QListView item ( cannot access)

PushButton at QListView item ( cannot access)

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.2k 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
    achak
    wrote on last edited by achak
    #1

    Hi all,
    I have very simple app created using Qt-Creator designer.
    The app is MainWindow with QListView and item's form. The form cosist icon, text and push button. The items are inserted to the list using QStyledItemDelegate delivered class. The items are displayed but the item buttons are not accesable. I cannot push on them and them do not change cursor on hover.

    The list view class construct and Add method:

    MessageList::MessageList(QWidget *parent) :
        QListView(parent)
    {
        auto *delegate = new Delegate(this);
    
        setModel(new QStandardItemModel(this));
        setItemDelegate(delegate);
    }
    
    void MessageList::Add(const QString &text, const QPixmap &pixmap)
    {
        auto *item = new QStandardItem(QIcon(pixmap), text);
    
       item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
        static_cast<QStandardItemModel *>(model())->appendRow(item);
    }
    
    

    The delegate's paint

    void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                         const QModelIndex &index) const
    {
        QPaintDevice* original_pdev_ptr = painter->device();
        QStyleOptionViewItem opt(option);
        initStyleOption(&opt, index);
    
       Message msg;
        msg.SetText(opt.text);
        msg.SetIcon(opt.icon, iconSize());
    
        msg.render(painter->device(), QPoint(option.rect.x()+16, option.rect.y()+16), QRegion(0, 0, option.rect.width(), option.rect.height()), QWidget::RenderFlag::DrawChildren);
        painter->begin(original_pdev_ptr);
    }
    

    I tried various setflag params and to msg.raise but without success.

    Thank you.

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

      Just because you paint something it doesn't mean that these paintings react on something.

      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
      • A Offline
        A Offline
        achak
        wrote on last edited by
        #3

        @Christian-Ehrlicher said in PushButton at QListView item ( cannot access):

        Just because you paint something it doesn't mean that these paintings react on something.

        How I can paint reactable button?
        // All buttons are connected to signals

        SGaistS 1 Reply Last reply
        0
        • A achak

          @Christian-Ehrlicher said in PushButton at QListView item ( cannot access):

          Just because you paint something it doesn't mean that these paintings react on something.

          How I can paint reactable button?
          // All buttons are connected to signals

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi

          @achak said in PushButton at QListView item ( cannot access):

          // All buttons are connected to signals

          How did you do that part ?

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

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi

            @achak said in PushButton at QListView item ( cannot access):

            // All buttons are connected to signals

            How did you do that part ?

            A Offline
            A Offline
            achak
            wrote on last edited by
            #5

            @SGaist said in PushButton at QListView item ( cannot access):

            Hi

            @achak said in PushButton at QListView item ( cannot access):

            // All buttons are connected to signals

            How did you do that part ?

            I create the listed item is using QT creator UI form. This code is from class:

            public slots:
                void on_pushButton_released();
            

            This is from the constructor:

                connect(ui->pushButton_2, SIGNAL(released()), this, SLOT(on_pushButton_released()));
            

            And this is the slot func:

            void Message::on_pushButton_released()
            {
                static int c=0;
                qDebug() << "Release: " << c;
                c++;
            }
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Your design looks a bit strange.

              Why do you need a QListView since you are essentially showing a vertical list of widgets for which you could use a QVBoxLayout ?

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

              A 1 Reply Last reply
              1
              • SGaistS SGaist

                Your design looks a bit strange.

                Why do you need a QListView since you are essentially showing a vertical list of widgets for which you could use a QVBoxLayout ?

                A Offline
                A Offline
                achak
                wrote on last edited by
                #7

                @SGaist said in PushButton at QListView item ( cannot access):

                Your design looks a bit strange.

                Why do you need a QListView since you are essentially showing a vertical list of widgets for which you could use a QVBoxLayout ?
                I have solution using the QVBoxLayout and scrollarea. There are hundreds of items in the list, we can see only three-four of them. All items are rendered in memory.

                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