Invisible QLineEdit receive Focus?!?
-
@django-Reinhard
Although I have never tried this, it does not sound right. Do you hide yourQLineEdit
s vialineEdit->hide()
? I would expect the tab key to skip such elements. Do you have just plainQLineEdit
s on some simple layout, or do you have something like they are inside aQTableWidget
? -
@django-Reinhard please provide a verifiable example.
-
@JonB said in Invisible QLineEdit receive Focus?!?:
Do you have just plain QLineEdits on some simple layout ...
Yes,
QLineEdit
withQGridLayout
...@eyllanesc said in Invisible QLineEdit receive Focus?!?:
please provide a verifiable example.
Sorry, but that would be too much work.
Look:The App consists of a center widget and several dockables. Center-widget is a stack and here the main widget of the
QScrollArea
manages 10 Editors in a FlowLayout.
My goal was to make the application usable without a mouse. This led to some peculiarities that are not known from mouse applications.... any way:
The number ofQLineEdits
is based on values read from ini-file and processed by some intermediate classes ... too complex to simplify in a hurryThe editor was created by form-designer of QtCreator and consists of
QLabel
,QLineEdit
andQGridLayout
. Taborder was specified in QtCreator too.The editor class (only problem related parts):
#include <dynwidget.h> #include <ui_Fixture.h> class QLineEdit; class AxisMask; class FixtureEdit : public DynWidget // , protected Ui_frame { public: FixtureEdit(const QString& title, const AxisMask& mask, QWidget* parent = nullptr); protected: void setupUi(DynWidget* parent); private: Ui::frame* ui; const AxisMask& m; };
constructor ...
FixtureEdit::FixtureEdit(const QString& title, const AxisMask& mask, QWidget* parent) : DynWidget(QString(), parent) , ui(new Ui::frame()) , m(mask) { setupUi(this); ui->title->setText(title); layout()->setContentsMargins(0, 0, 0, 0); }
... and setupUi (lX is a
QLabel
and edX theQLineEdit
):void FixtureEdit::setupUi(DynWidget* parent) { ui->setupUi(parent); ui->lX->setVisible(m.hasXAxis()); ui->lY->setVisible(m.hasYAxis()); ui->lZ->setVisible(m.hasZAxis()); ui->lA->setVisible(m.hasAAxis()); ui->lB->setVisible(m.hasBAxis()); ui->lC->setVisible(m.hasCAxis()); ui->lU->setVisible(m.hasUAxis()); ui->lV->setVisible(m.hasVAxis()); ui->lW->setVisible(m.hasWAxis()); ui->edX->setVisible(m.hasXAxis()); ui->edY->setVisible(m.hasYAxis()); ui->edZ->setVisible(m.hasZAxis()); ui->edA->setVisible(m.hasAAxis()); ui->edB->setVisible(m.hasBAxis()); ui->edC->setVisible(m.hasCAxis()); ui->edU->setVisible(m.hasUAxis()); ui->edV->setVisible(m.hasVAxis()); ui->edW->setVisible(m.hasWAxis()); }
last not least the ui-file:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>frame</class> <widget class="DynWidget" name="frame"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>233</width> <height>336</height> </rect> </property> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="lineWidth" stdset="0"> <number>3</number> </property> <layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0,0,0,0,0" columnstretch="0,0"> <property name="leftMargin"> <number>0</number> </property> <property name="topMargin"> <number>0</number> </property> <property name="rightMargin"> <number>0</number> </property> <property name="bottomMargin"> <number>0</number> </property> <property name="verticalSpacing"> <number>1</number> </property> <item row="5" column="1"> <widget class="QLineEdit" name="edA"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="7" column="0"> <widget class="QLabel" name="lC"> <property name="minimumSize"> <size> <width>25</width> <height>0</height> </size> </property> <property name="text"> <string>C</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> </item> <item row="8" column="1"> <widget class="QLineEdit" name="edU"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="10" column="1"> <widget class="QLineEdit" name="edW"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="3" column="0"> <widget class="QLabel" name="lY"> <property name="minimumSize"> <size> <width>25</width> <height>0</height> </size> </property> <property name="text"> <string>Y</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> </item> <item row="6" column="1"> <widget class="QLineEdit" name="edB"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="2" column="1"> <widget class="QLineEdit" name="edX"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="2" column="0"> <widget class="QLabel" name="lX"> <property name="minimumSize"> <size> <width>25</width> <height>0</height> </size> </property> <property name="text"> <string>X</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> </item> <item row="10" column="0"> <widget class="QLabel" name="lW"> <property name="minimumSize"> <size> <width>25</width> <height>0</height> </size> </property> <property name="text"> <string>W</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> </item> <item row="4" column="0"> <widget class="QLabel" name="lZ"> <property name="minimumSize"> <size> <width>25</width> <height>0</height> </size> </property> <property name="text"> <string>Z</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> </item> <item row="9" column="1"> <widget class="QLineEdit" name="edV"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="9" column="0"> <widget class="QLabel" name="lV"> <property name="minimumSize"> <size> <width>25</width> <height>0</height> </size> </property> <property name="text"> <string>V</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> </item> <item row="8" column="0"> <widget class="QLabel" name="lU"> <property name="minimumSize"> <size> <width>25</width> <height>0</height> </size> </property> <property name="text"> <string>U</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> </item> <item row="7" column="1"> <widget class="QLineEdit" name="edC"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="6" column="0"> <widget class="QLabel" name="lB"> <property name="minimumSize"> <size> <width>25</width> <height>0</height> </size> </property> <property name="text"> <string>B</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> </item> <item row="4" column="1"> <widget class="QLineEdit" name="edZ"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="3" column="1"> <widget class="QLineEdit" name="edY"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="5" column="0"> <widget class="QLabel" name="lA"> <property name="minimumSize"> <size> <width>25</width> <height>0</height> </size> </property> <property name="text"> <string>A</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> </item> <item row="1" column="0" colspan="2"> <widget class="QLabel" name="title"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="font"> <font> <pointsize>12</pointsize> <weight>75</weight> <bold>true</bold> </font> </property> <property name="frameShape"> <enum>QFrame::Panel</enum> </property> <property name="frameShadow"> <enum>QFrame::Raised</enum> </property> <property name="text"> <string>G54</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> </item> </layout> </widget> <customwidgets> <customwidget> <class>DynWidget</class> <extends>QWidget</extends> <header>dynwidget.h</header> <container>1</container> </customwidget> </customwidgets> <tabstops> <tabstop>edX</tabstop> <tabstop>edY</tabstop> <tabstop>edZ</tabstop> <tabstop>edA</tabstop> <tabstop>edB</tabstop> <tabstop>edC</tabstop> <tabstop>edU</tabstop> <tabstop>edV</tabstop> <tabstop>edW</tabstop> </tabstops> <resources/> <connections/> </ui>
-
@django-Reinhard said in Invisible QLineEdit receive Focus?!?:
Sorry, but that would be too much work.
Way, way too much detail. Nobody (other then you) wants to have to wade through this.
Reduce to 2 labels on a
QGridLayout
. Do yoursetVisible()
on each and see what happens to tabbing. If that functions correctly, work back up to your actual situation. If that does not function correctly, show non-functioning code with 2 labels. -
Hello!
You can try to set fields tab order by yourself using the
setTabOrder
method: https://doc.qt.io/qt-5/qwidget.html#setTabOrderFor example:
setTabOrder(ui->edB, ui->edA);
-
Hi,
@Cobra91151 said in Invisible QLineEdit receive Focus?!?:
you can try to set fields tab order by yourself
Thank you for that hint!
Ugly, but sounds like a workaround. I'll try that.
-
Hi,
@Cobra91151
thanks to your hint usage of the editor is a bit better, but still weird.I use this code:
int start = -1, first = 0, second = 1, mx = edits.size() - 1; do { while (first < mx) { if (m.hasAxis(first)) break; ++first; } second = first + 1; while (second < mx) { if (m.hasAxis(second)) break; ++second; } qDebug() << "set taborder" << first << "->" << second; QWidget::setTabOrder(edits.at(first), edits.at(second)); if (start < 0) start = first; first = second; } while (first < mx); // qDebug() << "set taborder" << second << "->" << start; // QWidget::setTabOrder(edits.at(second), edits.at(start));
and debug log reports:
set taborder 1 -> 2 set taborder 2 -> 3 set taborder 3 -> 8
Tab-key switches from first to last editfield as expected, but it needs 5 tab-key presses to turn from last to first edit.
When I uncomment both last two lines, debug log reports:
set taborder 1 -> 2 set taborder 2 -> 3 set taborder 3 -> 8 set taborder 8 -> 1
but order of editfields is (in drive letters) X, Z, A, W, Y, +5
So in sum still suboptimal.
-
I would suggest to store your edit fields in some container to keep the order, for example:
QHash
(https://doc.qt.io/qt-5/qhash.html#details). -
Hi,
@Cobra91151 said in Invisible QLineEdit receive Focus?!?:
I would suggest to store your edit fields in some container
They are already in a container (QList) for sequential access.
Don't know whether I got you right.
Probably it would be better, not using forms by qtcreator but use programmatically created elements.That would be possible, but was not the idea. Just loading another ini-file could lead to completely different field pattern.
I have the same usecase on the position-display, but there I don't have user input, so that works without issue.But ok, creating the entire editor on my own would skip the odd behaviour.
OK, thank you for the hint!
-
Just to close this:
I solved the problem with this solution