[Interest] More on table problem

Turtle Creek Software support at turtlesoft.com
Fri Jun 11 17:51:13 CEST 2021


If I understand this code correctly, it's putting the button inside the
cell. Unfortunately, there isn't enough room to do that.
The table only shows the QLineEdits.  When you click in a cell to edit, the
button appears next to it, over the neighboring cell(s).
However, maybe there is a container we can put the button into, that will
act as a click barrier.  Something less extreme than a dialog.
Casey McD

On Fri, Jun 11, 2021 at 10:05 AM Volker Hilsheimer <volker.hilsheimer at qt.io>
wrote:

> > 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210611/e2d22cea/attachment.html>


More information about the Interest mailing list