Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I add QTableWidget properties to a custom QWidget designer widget?
Forum Updated to NodeBB v4.3 + New Features

How can I add QTableWidget properties to a custom QWidget designer widget?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 834 Views
  • 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.
  • K Offline
    K Offline
    KidTrent
    wrote on last edited by KidTrent
    #1

    I've created a custom designer widget that has a QTableWidget and two QPushButton's. I would like the QTableWidget properties and QPushButton properties to be configurable in the custom widgets Qt Designer properties panel. How can I do this?

    I thought simply using a Q_PROPERTY macro would work, but it doesn't appear to have any effect as the properties don't appear after I restart Qt with the updated DLL.

    Q_PROPERTY(QTableWidget* tableWidget READ GetTableWidget);
    

    Here is the code for the widget, the plugin code is still the default that the wizard created/

    EditableWidget.h

    #ifndef EDITABLETABLEWIDGET_H
    #define EDITABLETABLEWIDGET_H
    
    #include <QDialog>
    
    class QTableWidget;
    
    namespace Ui {
    class EditableTableWidget;
    }
    
    class EditableTableWidget : public QDialog
    {
        Q_OBJECT
        Q_PROPERTY(QTableWidget* tableWidget READ GetTableWidget);
    
    public:
        explicit EditableTableWidget(
                QWidget *parent = nullptr);
    
        ~EditableTableWidget();
    
    private:
        QString GetBtnText() const;
    
        void SetBtnText(QString btnText);
    
        QTableWidget* GetTableWidget() const;
    
        Ui::EditableTableWidget *ui;
    };
    
    #endif // EDITABLETABLEWIDGET_H
    

    EditableWidget.cpp

    #include "EditableTableWidget.h"
    #include "ui_EditableTableWidget.h"
    
    
    EditableTableWidget::EditableTableWidget(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::EditableTableWidget)
    {
        ui->setupUi(this);
    }
    
    EditableTableWidget::~EditableTableWidget()
    {
        delete ui;
    }
    
    QString EditableTableWidget::GetBtnText() const
    {
        return ui->AddRowBtn->text();
    }
    
    void EditableTableWidget::SetBtnText(QString btnText)
    {
        ui->AddRowBtn->setText(btnText);
    }
    
    QTableWidget* EditableTableWidget::GetTableWidget() const
    {
        return ui->TableWidget;
    }
    

    EditableWidget.h

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>EditableTableWidget</class>
     <widget class="QDialog" name="EditableTableWidget">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>280</width>
        <height>240</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>Dialog</string>
      </property>
      <widget class="QTableWidget" name="TableWidget">
       <property name="geometry">
        <rect>
         <x>10</x>
         <y>10</y>
         <width>261</width>
         <height>192</height>
        </rect>
       </property>
      </widget>
      <widget class="QPushButton" name="AddRowBtn">
       <property name="geometry">
        <rect>
         <x>190</x>
         <y>210</y>
         <width>80</width>
         <height>21</height>
        </rect>
       </property>
       <property name="text">
        <string>Add Row</string>
       </property>
      </widget>
      <widget class="QPushButton" name="DeleteRowBtn">
       <property name="geometry">
        <rect>
         <x>100</x>
         <y>210</y>
         <width>80</width>
         <height>21</height>
        </rect>
       </property>
       <property name="text">
        <string>Delete Row</string>
       </property>
      </widget>
     </widget>
     <resources/>
     <connections/>
    </ui>
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      How should the designer know what to do with a pointer to a Qt class?
      You have to expose the properties you want by yourself.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • K Offline
        K Offline
        KidTrent
        wrote on last edited by KidTrent
        #3

        Re: How can I add QTableWidget properties to a custom QWidget designer widget?

        Is there not a way to automatically expose all the available properties when a pointer is provided...?

        Hmm, then how can I make it so the user can specify the Column names? For example when you double click a QTableWidget, you can add/remove/edit Columns/Rows/Items.... but if the QTableWidget is in my CustomWidget, this doesn't work (instead the object name field opens up)...

        I guess my questions is now... how can I change the double click functionality in the designer for my custom widget to activate the functionality on the table I created within it?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bonnie
          wrote on last edited by Bonnie
          #4

          I haven't tried that but I'm sure that at least you need to write and build your own Qt designer plugin.
          https://doc.qt.io/qt-5/designer-creating-custom-widgets.html

          1 Reply Last reply
          1
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by Christian Ehrlicher
            #5

            @KidTrent said in How can I add QTableWidget properties to a custom QWidget designer widget?:

            Is there not a way to automatically expose all the available properties when a pointer is provided...?

            No, it's not since it's not a common usecase - feel free to provide a patch for designer.

            For example when you double click a QTableWidget

            Use a proper model instead convenience widgets

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            K 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @KidTrent said in How can I add QTableWidget properties to a custom QWidget designer widget?:

              Is there not a way to automatically expose all the available properties when a pointer is provided...?

              No, it's not since it's not a common usecase - feel free to provide a patch for designer.

              For example when you double click a QTableWidget

              Use a proper model instead convenience widgets

              K Offline
              K Offline
              KidTrent
              wrote on last edited by
              #6

              @Christian-Ehrlicher

              Great, thanks for the help/clarification!

              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