qcombobox

Add QObject in the combo box of Qt

谁说我不能喝 提交于 2019-12-04 18:24:36
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. 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::fromValue(myClass)); And get it back: this->ui->combobox->itemData(x).value<MyClass*>(); Above answer syntax is

Selecting QComboBox in QTableWidget

怎甘沉沦 提交于 2019-12-04 17:42:04
问题 One cell in each row of a QTableWidget contains a combobox for (each row in table ... ) { QComboBox* combo = new QComboBox(); table->setCellWidget(row,col,combo); combo->setCurrentIndex(node.type()); connect(combo, SIGNAL(currentIndexChanged(int)),this, SLOT(changed(int))); .... } In the handler function ::changed(int index) I have QComboBox* combo=(QComboBox*)table->cellWidget(_row,_col); combo->currentIndex() To get back a copy of the combobox and get the new selection. But I can't get the

QComboBox elided text on selected item

霸气de小男生 提交于 2019-12-04 17:15:32
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 fontMetric(painter.font()); const QString elidedText = QAbstractItemDelegate::elidedText(fontMetric, rect.width(

Style QComboBox's sub-control down-arrow when mouse is hovering over the QComboBox via QSS

旧街凉风 提交于 2019-12-04 06:21:11
问题 I know how to style QComboBox when mouse is hovering by doing: pComboBox->setStyleSheet(pComboBox->styleSheet()+QString(" QComboBox:hover{css style here}")) And I also know to style QComboBox 's sub-control down-arrow's style via: pComboBox->setStyleSheet(pComboBox->styleSheet()+QString(" QComboBox::down-arrow{css style here}")) But I don't know how to style QComboBox 's sub-control down-arrow when the mouse is hovering over the QComboBox via QSS . Does anybody have an idea? 回答1: I don't know

“QComboBox Pop-up” expanding and QtWebkit

时光毁灭记忆、已成空白 提交于 2019-12-04 03:30:32
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 j = this->count(); for( int i=0; i < j; ++i ) { const int textWidth = fontMetrics.width( this->itemText

Selecting QComboBox in QTableWidget

一世执手 提交于 2019-12-03 10:33:59
One cell in each row of a QTableWidget contains a combobox for (each row in table ... ) { QComboBox* combo = new QComboBox(); table->setCellWidget(row,col,combo); combo->setCurrentIndex(node.type()); connect(combo, SIGNAL(currentIndexChanged(int)),this, SLOT(changed(int))); .... } In the handler function ::changed(int index) I have QComboBox* combo=(QComboBox*)table->cellWidget(_row,_col); combo->currentIndex() To get back a copy of the combobox and get the new selection. But I can't get the row/col. None of the table cellXXXX signals is emitted when an embedded item is selected or changed and

Style QComboBox's sub-control down-arrow when mouse is hovering over the QComboBox via QSS

南楼画角 提交于 2019-12-02 10:31:08
I know how to style QComboBox when mouse is hovering by doing: pComboBox->setStyleSheet(pComboBox->styleSheet()+QString(" QComboBox:hover{css style here}")) And I also know to style QComboBox 's sub-control down-arrow's style via: pComboBox->setStyleSheet(pComboBox->styleSheet()+QString(" QComboBox::down-arrow{css style here}")) But I don't know how to style QComboBox 's sub-control down-arrow when the mouse is hovering over the QComboBox via QSS . Does anybody have an idea? I don't know is QSS powerful enough to do this(I think no), but with eventfilter you can do this very easy: bool

Items disappears from combo box when I read them from model

纵然是瞬间 提交于 2019-12-02 09:28:40
问题 I have QComboBox and I set QStandardItemModel because I need multi-select check-boxes in it. Problem is that when I read text value and check state of items in comboBox, they disappear from combo. This is how I set model to comboBox: areas = ["Area one", "Area two", "Area three", "Area four"] model = QtGui.QStandardItemModel(4, 1)# 4 rows, 1 col for i,area in enumerate(areas): item = QtGui.QStandardItem(area) item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) item.setData

how to add stylesheet for separator in QCombobox

為{幸葍}努か 提交于 2019-12-02 04:47:49
问题 i added two items in a qcombobox with a separator addItem("New"); addItem("Delete"); insertSeparator(2); in order to highlight the selection of item with different style i used QLIstView for the QComboBox view with the stylesheet as QListView * listView = new QListView(this); this->setView(listView); listView->setStyleSheet("QListView::item { \ color: black; \ background: white; } \ QListView::item:selected { \ color: white; \ background-color: #0093D6 \ } \ "); now the problem is the

how to add stylesheet for separator in QCombobox

耗尽温柔 提交于 2019-12-02 01:07:26
i added two items in a qcombobox with a separator addItem("New"); addItem("Delete"); insertSeparator(2); in order to highlight the selection of item with different style i used QLIstView for the QComboBox view with the stylesheet as QListView * listView = new QListView(this); this->setView(listView); listView->setStyleSheet("QListView::item { \ color: black; \ background: white; } \ QListView::item:selected { \ color: white; \ background-color: #0093D6 \ } \ "); now the problem is the separator is not visible at all .. it is showing a empty white space between the items . I'm not good with