Insert QWidget in a QTableWidget
-
Hi!
I created a
AudioItem
class, fromQWidget
, added a few elements (buttons, labels, slider, etc), and I need to insert instances into aQTableWidget
object calledtblAudio
, which was configured like this:<widget class="QTableWidget" name="tblAudios"> <property name="styleSheet"> <string notr="true">background-color: rgb(255, 255, 255);</string> </property> <property name="frameShape"> <enum>QFrame::NoFrame</enum> </property> <property name="frameShadow"> <enum>QFrame::Plain</enum> </property> <property name="verticalScrollBarPolicy"> <enum>Qt::ScrollBarAlwaysOff</enum> </property> <property name="horizontalScrollBarPolicy"> <enum>Qt::ScrollBarAlwaysOff</enum> </property> <property name="sizeAdjustPolicy"> <enum>QAbstractScrollArea::AdjustToContents</enum> </property> <property name="autoScrollMargin"> <number>40</number> </property> <property name="editTriggers"> <set>QAbstractItemView::NoEditTriggers</set> </property> <property name="showDropIndicator" stdset="0"> <bool>false</bool> </property> <property name="selectionMode"> <enum>QAbstractItemView::SingleSelection</enum> </property> <property name="selectionBehavior"> <enum>QAbstractItemView::SelectRows</enum> </property> <property name="verticalScrollMode"> <enum>QAbstractItemView::ScrollPerItem</enum> </property> <property name="showGrid"> <bool>true</bool> </property> <property name="gridStyle"> <enum>Qt::SolidLine</enum> </property> <property name="cornerButtonEnabled"> <bool>false</bool> </property> <property name="rowCount"> <number>0</number> </property> <property name="columnCount"> <number>1</number> </property> <attribute name="horizontalHeaderVisible"> <bool>false</bool> </attribute> <attribute name="horizontalHeaderHighlightSections"> <bool>false</bool> </attribute> <attribute name="verticalHeaderVisible"> <bool>false</bool> </attribute> <attribute name="verticalHeaderHighlightSections"> <bool>false</bool> </attribute> <column/> </widget>
In the constructor of the form where
tblAudios
is created, I wrote:ui->tblAudios->setColumnWidth(0,250); ui->tblAudios->resizeRowsToContents(); ui->tblAudios->horizontalHeader()-> setSectionResizeMode(0,QHeaderView::ResizeMode::Stretch);
And the code that inserts an
AudioItem
intotblAudios
is like this:AudioItem * _audio_item (new AudioItem(...); ui->tblAudios->insertRow(ui->tblAudios->rowCount()); int _row = ui->tblAudios->rowCount() - 1; ui->tblAudios->setRowHeight(_row, _audio_item->height() + 250); ui->tblAudios->setCellWidget(_row, 0, _audio_item);
My problem: if I use a constant less than
250
,AudioItem
is "cut", I mean, it does not displayed completely in larger cell phones. But in a smaller, this values makesAudioItem
too tall.I tried a couple of things, like removing the
resizeRowsToContents
in the constructor, but I can not assure that the items in the table are correctly vertically sized.Could anyone help me with that?
[Locked as duplicate of https://forum.qt.io/topic/75850/qlistwidget-row-size-with-a-custom-qlistwidgetitem ~kshegunov]