qcombobox

PyQt Enable/Disable elements in a QComboBox

五迷三道 提交于 2019-12-07 02:54:38
问题 I have a QComboBox that list all Windows' drive letters and let the user choose among them. During the execution, we need to enable or disable some of the letters (without removing them). Here is the basic code : all_letters = ["{}:".format(chr(i)) for i in range(90, 64, -1)] # Z: -> A: all_letters.insert(0, "") cb_letter = QtGui.QComboBox() for l in all_letters: cb_letter.addItem(l) cb_letter.setCurrentIndex(0) I could find a kind of solution (which sounds really complicated) for just

Qt, How do I change the text color of one item of a QComboBox? (C++)

穿精又带淫゛_ 提交于 2019-12-06 19:43:30
问题 I cannot figure out how to change the text color of one particular item of a QComboBox. I was able to change the Background color of an item: comboBox->setItemData(i, Qt::green, Qt::BackgroundRole); ( Qt::ForegroundRole had no effect at all, Qt 4.6, Ubuntu 10.04) and I was able to change the text color of all items with a stylesheet but I cannot figure out how to change the text color of one specified item. Thanks for your Help! 回答1: It's almost like you propose, but you have to change the

Error in model view implemention of GUI in pyqt

吃可爱长大的小学妹 提交于 2019-12-06 13:15:33
the following sample code is crashing with this error when I close the application: QBasicTimer::start: QBasicTimer can only be used with threads started with QThread here is my code : import sys from PyQt4 import QtGui ,QtCore app = QtGui.QApplication(sys.argv) data=[] data.append("one") model=QtGui.QStringListModel(data) combobox=QtGui.QComboBox() combobox.show() combobox.setModel(model) sys.exit(app.exec_()) I found out that's about using model but I don't know how to fix it. edited: os : win 7 64bit pyqt4 The program is not "crashing": it is merely printing an error message during the

QComboBox elided text on selected item

懵懂的女人 提交于 2019-12-06 10:55:05
问题 So, I have a QComboBox . If the currentText() is too long for the widget then I want to show an ellipsis. Like this : So : void MyComboBox::paintEvent(QPaintEvent * ) { QStylePainter painter(this); QStyleOptionComboBox opt; initStyleOption(&opt); painter.drawComplexControl(QStyle::CC_ComboBox, opt); QRect rect = this->rect(); //this is not ideal rect.setLeft(rect.left() + 7); rect.setRight(rect.width() - 15); // QTextOption option; option.setAlignment(Qt::AlignVCenter); QFontMetrics

“QComboBox Pop-up” expanding and QtWebkit

我与影子孤独终老i 提交于 2019-12-05 21:32:15
问题 In Firefox/Chrome/InternetExplorer/Safari/Opera pop-ups from the combobox expand as the content, see Firefox picture: QComboBox pop-up does not expand the content. Pop-ups are limited by the size of QComboBox , see QWebView picture: So I implemented the QComboBox::showPopup : void newQComboBox::showPopup() { int width = this->width(); this->view()->setTextElideMode( Qt::ElideNone ); const int iconSize = this->iconSize().width(); const QFontMetrics fontMetrics = this->fontMetrics(); const int

Qt - How to use rich text in a QComboBox?

限于喜欢 提交于 2019-12-05 10:21:14
I am trying to use rich text in a QComboBox but it does not support it. Perhaps I should write a subclass? But I am unsure on what I would need to override as I have never done anything like this before. Please help. Thanks! Mike Hordecki I think custom delegate class is the answer. The solution is to simply replace standard drawing routine with your own (using i.e. QLabel). There was a similar question here: QListView/QListWidget with custom items and custom item widgets 来源: https://stackoverflow.com/questions/2476581/qt-how-to-use-rich-text-in-a-qcombobox

Setting QStyleOptionComboBox.currentText does not have any effect on the drawn widget

时光毁灭记忆、已成空白 提交于 2019-12-05 09:38:37
I want to draw a QComboBox inside a delegate, which works fine except that I can't figure out how to draw the inital text that's visible inside the combo box. The documentation says that QStyleOptionComboBox.currentText holds: "the text for the current item of the combo box." but setting the variable does not have any effect. This is my code: void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyleOptionComboBox comboBoxOption; comboBoxOption.rect = option.rect; comboBoxOption.state = option.state; comboBoxOption.state |= QStyle:

PyQt Enable/Disable elements in a QComboBox

妖精的绣舞 提交于 2019-12-05 06:14:28
I have a QComboBox that list all Windows' drive letters and let the user choose among them. During the execution, we need to enable or disable some of the letters (without removing them). Here is the basic code : all_letters = ["{}:".format(chr(i)) for i in range(90, 64, -1)] # Z: -> A: all_letters.insert(0, "") cb_letter = QtGui.QComboBox() for l in all_letters: cb_letter.addItem(l) cb_letter.setCurrentIndex(0) I could find a kind of solution (which sounds really complicated) for just disabling an entry here but no way to enable it back. What would be the best way to enable and disable any

Qt, How do I change the text color of one item of a QComboBox? (C++)

烂漫一生 提交于 2019-12-05 00:52:57
I cannot figure out how to change the text color of one particular item of a QComboBox. I was able to change the Background color of an item: comboBox->setItemData(i, Qt::green, Qt::BackgroundRole); ( Qt::ForegroundRole had no effect at all, Qt 4.6, Ubuntu 10.04) and I was able to change the text color of all items with a stylesheet but I cannot figure out how to change the text color of one specified item. Thanks for your Help! Lefteris Banos It's almost like you propose, but you have to change the role to Qt::TextColorRole . comboBox->setItemData(0, QBrush(Qt::red), Qt::TextColorRole); I

How can I change the contents of one QComboBox depending on another QComboBox in PyQt5?

房东的猫 提交于 2019-12-04 21:17:53
I write program on python3 that will calculate thermodynamic properties. This is piece of GUI "Выбранное вещество" is a selected substance like 1-Butene, water, ammonia and etc. "Первый параметр" is a first parameter. User will choose parameters like pressure, temperature, density and etc, and unit of measurement like Pa, MPa, bar (if it's pressure) and etc. So I don't know one thing: i want that if user chose pressure('Давление (P)') in top combobox, depending on this, suitable units of measure were chosen in small combobox. What have i already done: create 2 files testGUI.py - there is all