PushButton at QListView item ( cannot access)
-
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.
-
Just because you paint something it doesn't mean that these paintings react on something.
-
@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 -
@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 signalsHi
@achak said in PushButton at QListView item ( cannot access):
// All buttons are connected to signals
How did you do that part ?
-
Hi
@achak said in PushButton at QListView item ( cannot access):
// All buttons are connected to signals
How did you do that part ?
@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++; } -
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 ?
-
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 ?
@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.