qcombobox

How do I set the QComboBox width to fit the largest item?

非 Y 不嫁゛ 提交于 2019-12-23 06:48:36
问题 I have a QComboBox that I fill with QString using: comboBox->addItem(someString); When I start my GUI application the width of the QComboBox is always 70, even if the smallest item is much larger. How can I dynamically set the width of a QComboBox , for instance, to the largest QString within the comboBox ? Edit: After some further testing I found the following solution: // get the minimum width that fits the largest item. int width = ui->sieveSizeComboBox->minimumSizeHint().width(); // set

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

。_饼干妹妹 提交于 2019-12-22 05:59:26
问题 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;

Add QObject in the combo box of Qt

自闭症网瘾萝莉.ら 提交于 2019-12-22 00:18:04
问题 I have a custom class I created, say MyClass. Now how to add a reference to MyClass's reference as second parameter in the combo box below: this->ui->comboBox->addItem("item-1", ); Purpose is to when item changed even is fired, i want to get that specific class instance of MyClass and process accordingly. 回答1: First you need to use Q_DECLARE_METATYPE(MyClass*), so that the type can be used in QVariant . Then you can add the item like this: this->ui->comboBox->addItem("item-1", QVariant:

pyQT Combobox print output upon changed

十年热恋 提交于 2019-12-20 04:32:51
问题 I want to create an event (print in this case) based on which combox and which row in the combox. I had a look on this old post and made some extension. Does it make some sense? When I press "second" in the left combox I want the output "0, 2" and when I press the "second" in the right combox I want the output "1, 2". from PyQt4 import QtCore, QtGui import sys class MyClass(object): def __init__(self, arg): super(MyClass, self).__init__() self.row = arg self.col = [] def add_column(self, col)

PyQt5 ComboBox - how do I set the color of CurrentText without affecting the dropdown list?

谁都会走 提交于 2019-12-19 10:16:29
问题 The following snippet correctly sets the colors of individual entries in the ComboBox dropdown list. However, when an item is selected and transferred to the CurrentText field, all of the entries in the dropdown change to the color of CurrentText. How do I transfer the color of an entry to be displayed as CurrentText without affecting the dropdown list? import sys from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * class ComboDemo(QWidget): def __init__(self):

QComboBox drop-down list - set selected item style

血红的双手。 提交于 2019-12-19 05:54:56
问题 Is it possible to set selected item style (Qt style sheet) of the QComboBox drop-down list? 回答1: The solution is to create a ListView object set its stylesheet use it as the view of the ComboBox Here is how: int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow * mainWindow = new QMainWindow(); QComboBox * combo = new QComboBox(mainWindow); QListView * listView = new QListView(combo); combo->addItem("foo"); combo->addItem("bar"); combo->addItem("foobar"); combo->addItem

PyQT5 QComboBox - get value of combobox

橙三吉。 提交于 2019-12-19 04:05:58
问题 I am still very new to Qt but I am developing a type of calculator and want to use a combobox to select a coefficient. I have had success creating a combobox with a liststore in pyGT but it appears pyQT is quite different. I am having a hard time wrapping my head around the data models and list models. Essentially I want to have a name show up in the combobox and have the value of that name get passed to the calculator equation. Everything I have seen so far has been just for single entries

How can I get the selected VALUE out of a QCombobox?

好久不见. 提交于 2019-12-18 10:22:02
问题 In Qt, I can get the selected text of a QComboBox by using the combobox->currentText() method. How can I get the selected value ? I searched for help but I couldn't find a method currentData() which I expected to find. I could only find combobox->currentIndex() Is there a smarter way to do it other than combobox->itemData(combobox->currentIndex()) ? Update: This is no longer necessary as of Qt 5. A currentData() method has been added http://doc.qt.io/qt-5/qcombobox.html#currentData-prop 回答1:

How to change the size of a QComboBox's QScrollBar?

你离开我真会死。 提交于 2019-12-18 07:07:43
问题 I'm using a QComboBox with some items to the point that, when the widget that shows all available items in the QComboBox appears, only some of the items are visible with the other accesible through a QScrollBar. The problem is that the QScrollBar is to thin and I want to make it larger. I did some research on the web and I did found some ways to change the QScrollBar's width (see references below), but the problem is that I simply can't find the method to access the QComboBox's QScrollBar. So

How to set non-selectable default text on QComboBox?

爱⌒轻易说出口 提交于 2019-12-18 04:34:27
问题 Using a regular QComboBox populated with items, if currentIndex is set to -1 , the widget is empty. It would be very useful to instead have an initial descriptive text visible in the combo box(e.g. "--Select Country--", "--Choose Topic--", etc.) which is not shown in the dropdown list. I couldn't find anything in the documentation, nor any previous questions with answers. 回答1: It doesn't appear that case was anticipated in the Combo Box API. But with the underlying model flexibility it seems