Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Insert QWidget in a QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Insert QWidget in a QTableWidget

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 637 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • canellasC Offline
    canellasC Offline
    canellas
    wrote on last edited by A Former User
    #1

    Hi!

    I created a AudioItem class, from QWidget, added a few elements (buttons, labels, slider, etc), and I need to insert instances into a QTableWidget object called tblAudio, 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 into tblAudios 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 makes AudioItem 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]

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved