Disabling QComboBox in pyqt - pyqt

Is it possible to disable QComboBox in pyqt like we can do it in Win Forms(C#) since I could not find any option in the QComboBox manual. I want to enable QcomboBox only when admin logins.

I found the answer to my question,
QComboBox.setEnabled(False) # disable comboBox
and
QComboBox.setEnabled(True) # enable comboBox

You can also do :
QComboBox.setDisabled(True)
QComboBox.setDisabled(False)

Related

PYQT change clearButton in QLineEdit (w/wht Qt Designer)

Since I updated python from 3.8 to 3.10 (with Linux Ubuntu 22.04), clear button in QlineEdit widget has become an ugly red cross. It was before a nice dark kind of rectangular button with a small cross inside.
I wish I could switch back to the previous clear button without having to create a custom button, because the red cross is kind of disturbing as it seems to indicate an error in what you write in the QLineEdit widget.
Is there a way to do that in Qt Designer or programmatically?
It seems a bit unlikely that just updating Python would affect the icon.
The update probably involved other packages along with it (or they need rebuilding, they were uninstalled due to incompatibilities, etc), so I'd suggest to check that first.
In any case, you can set the icon using a specific stylesheet you could set for the top level window or even the application, so that it will be used for any QLineEdit with the clear button enabled:
QLineEdit > QToolButton {
qproperty-icon: url(/path/to/icon.png);
}
Note that this will override all icons of QLineEdit, including those used for custom actions, so in that case you must explicitly set the object name of the button and use the proper selector in the QSS:
# this assumes that the clearButtonEnabled property is already set,
# otherwise it will crash
lineEdit.findChild(QToolButton).setObjectName('clearButton')
lineEdit.setStyleSheet('''
QLineEdit > QToolButton#clearButton {
qproperty-icon: url(/path/to/icon.png);
}
''')
Also, see this related answer for other alternatives.

disable editing in QSpinbox but enable arrows

I have a QSpinBox in which I want to enable the arrows (for up and down values) but disable inserting data by the user.
I've tried using this:
QtGui.QSpinBox.setReadOnly(True)
But it doesn't work. All is disabled and the arrows are 'stuck'.
If you set the spin-box readonly, it will disable eveything. Instead, just set the line-edit readonly, and then buttons will still work:
spinbox.lineEdit().setReadOnly(True)
you can block spinboxes editor by QtGui.QSpinBox.lineEdit().setEnabled(False).
edit: and set font color and background-color:
spinbox.lineEdit().setStyleSheet('color: black; background-color: white;')
In case someone looking for an answer for this problem in C++ come here (like me), the other answers are not straightforward because QSpinBox::lineEdit() is a protected member (so it would require to also extend the class).
What worked for me was:
auto l1SpinBox = new QSpinBox(this);
auto lineEdit = l1SpinBox->findChild<QLineEdit*>();
lineEdit->setReadOnly(true);
lineEdit->setFocusPolicy(Qt::NoFocus);
connect(l1SpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), l1SpinBox,
[&, lineEdit](){lineEdit->deselect();}, Qt::QueuedConnection);
setReadOnly alone may do the trick for you. However in my case, I wanted to improve UI making it also not focusable, and then hiding the selection when the value changes.

hide menu and search button from kindle fire

Is there any way to hide menu and search buttons from Kindle Fire? This (Kindle Fire Customize Soft Key menu) says there's no way to do that, but i hope something has changed since then.
Thanks!
The overflow menu is automatic and controlled by the OS (similar to the Action menu on devices based on the default Android experience). The search icon is fixed and will either take the user to the platform search or you can override it following the instructions here.
You may also be able to achieve the effect you are looking for with one of the Full Screen Modes available to Kindle developers.
Do you have a sample of the code that is failing to hide the overflow menu appropriately?

PyQT Dialog Window with Toolbar

What is the standard approach of adding a toolbar to a dialog window in PyQT? I seem to be able to add toolbars only to a main window class.
Unfortunately this feature doesn't seem to be supported. See
Can you add a toolbar to QDialog? for answers to the same situation but in C++ and Qt.
However maybe you can just use a QMainWindow as a dialog window with a toolbar?

Cannot edit button labels in Glade 3.14.0

I cannot edit the buttons label in glade. They are disabled. How can i fix this? Here is the screen shot;
This has been answered here. In summary, you now need to add a Related Action and disable Use Action Appearance to be able to edit a button's label in Glade.
In addition to what David Planella added above, you can also open the .glade file using a text editor and manually edit the label text. I just tried it and it works.

Resources