QComboBox does not update size
-
Hello!
I have a problem with the QComboBox. I use two Combo Boxes with different content in a Dialog. Below every Box, there is a "show all" checkbox, to show more content.
I fill the ComboBox with items and if I exec(), everything is fine (i.e. the ComboBox has the right size).
The problem occurs if i now press the "show all"-checkboxes, because the ComboBox does not change its size, even if the items are now larger.
I tried many things (SizePolicy, updateGeometry, adjustSize etc.), ones I call exec(), the size of the ComboBox seems unchangeable :(
Heres some of my code, if you need more, let me know:@matchDialog::matchDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::matchDialog)
{
ui->setupUi(this);connect(ui->buttonBox,SIGNAL(accepted()),this,SLOT(ok())); connect(ui->buttonBox,SIGNAL(rejected()),this,SLOT(cancel())); connect(ui->checkBoxA,SIGNAL(toggled(bool)),this,SLOT(showAllA(bool))); connect(ui->checkBoxV,SIGNAL(toggled(bool)),this,SLOT(showAllV(bool)));
}
void matchDialog::addDevice(QString type, QString name,int index){
if (type == "audioDevice"){
audio << QPair<QString, int> (name,index);
ui->comboBoxAudio->addItem(name,QVariant(index));
}else{
ui->comboBoxVideo->addItem(name,QVariant(index));
video << QPair<QString, int> (name,index);
}
all << QPair <QString, int>(name,index);}
void matchDialog::showAllA(bool checked){
ui->comboBoxAudio->clear();
if(checked)
for(int i=0;i< all.size();i++)
ui->comboBoxAudio->addItem(all.at(i).first,QVariant(all.at(i).second));
else
for(int i=0;i< audio.size();i++)
ui->comboBoxAudio->addItem(audio.at(i).first,QVariant(audio.at(i).second));this->adjustSize();
}
void matchDialog::showAllV(bool checked){
ui->comboBoxVideo->clear();
if(checked)
for(int i=0;i< all.size();i++)
ui->comboBoxVideo->addItem(all.at(i).first,QVariant(all.at(i).second));
else
for(int i=0;i< video.size();i++)
ui->comboBoxVideo->addItem(video.at(i).first,QVariant(video.at(i).second));this->adjustSize();
}@
Thank you and Greetings
Matthias -
Update & Bump:
Things are getting weirder. Now I tried calling "this->adjustSize();" at the end of "matchDialog::showAllV" and "matchDialog::showAllA".
The result: If i click on the "checkBoxV" AND THEN on "checkBoxA", the size is adjusted properly. If I just click "checkBoxV" muliple times WIHTOUT clicking "checkBoxA", the size is adjust the wrong way (i.e. too small for big contents, too big for small contents).I hope anyone can help, the problem is really annoying :(.
-
Thank you for your reply :)
I don't know where the problem could be, so i post the full ui file:
@<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>matchDialog</class>
<widget class="QDialog" name="matchDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>204</width>
<height>125</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBoxVideo">
<property name="title">
<string>Video-Device</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QComboBox" name="comboBoxVideo">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxVisibleItems">
<number>10</number>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxV">
<property name="text">
<string>Show All</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxAudio">
<property name="title">
<string>Audio-Device</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QComboBox" name="comboBoxAudio">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxA">
<property name="text">
<string>Show All</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>matchDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>matchDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
@