[Interest] More on table problem
Volker Hilsheimer
volker.hilsheimer at qt.io
Fri Jun 11 16:05:12 CEST 2021
> On 11 Jun 2021, at 13:52, Turtle Creek Software <support at turtlesoft.com> wrote:
>
> Here's more info on the weird QTableWidget problem we're seeing.
>
> One of our data entry fields uses combination of widgets: a QLineEdit subclass with a linked QToolButton subclass next to it, and a QListWidget subclass that drops down underneath. It acts kinda like a combo box, but better for really long lists. The whole assembly works properly in regular data entry screens. Clicking on button or list changes values in the line edit field.
>
> We use setCellWidget to put the same QLineEdit subclass into a QTableWidget cell. The button and list appear properly, but the button does not catch mouse clicks. They go to the cell behind the button instead.
>
> We use signals/slots to connect the clicked signal, but don't fiddle with events otherwise.
>
> Casey McD
This works fine:
#include <QtWidgets>
class CellWidget : public QWidget
{
public:
CellWidget()
{
QLineEdit *le = new QLineEdit;
QToolButton *tb = new QToolButton;
QMenu *toolMenu = new QMenu;
toolMenu->addAction(new QAction("Action 1", this));
toolMenu->addAction(new QAction("Action 2", this));
toolMenu->addAction(new QAction("Action 3", this));
tb->setPopupMode(QToolButton::InstantPopup);
tb->setMenu(toolMenu);
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addWidget(le);
hbox->addWidget(tb);
setContentsMargins(0, 0, 0, 0);
hbox->setContentsMargins(0, 0, 0, 0);
setLayout(hbox);
}
QSize minimumSizeHint() const { return QSize(100, 100); }
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QTableWidget table(10, 10);
table.setCellWidget(5, 5, new CellWidget);
table.show();
return app.exec();
}
Volker
More information about the Interest
mailing list