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. Custom Widget not taking entire space

Custom Widget not taking entire space

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 584 Views 2 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.
  • D Offline
    D Offline
    Dev-G
    wrote on last edited by Chris Kawa
    #1

    Hi I am new to QT, below I created a custom table widget which inherit from QTableWidget.

    class TransTable : public QTableWidget {
        Q_OBJECT
    public:
        TransTable(int gNumOfTX , int gNumOfRX);
        ~TransTable();
    public slots:
        void UpdateTrans(QTableWidget *trans, int16_t *data);
    private:
        QTableWidget *mTransTable;
    };
    
    TransTable::TransTable(int gNumOfTX, int gNumOfRX)
    {
        mTransTable = new QTableWidget(this);
        mTransTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    
        mTransTable->setRowCount(gNumOfTX + 2);
        mTransTable->setColumnCount(gNumOfRX + 2);
        int nRows = mTransTable->rowCount();
        int nCols = mTransTable->columnCount();
    
        mTransTable->setHorizontalHeaderLabels(headers);
        mTransTable->horizontalHeader()->setVisible(false);
        mTransTable->verticalHeader()->setVisible(false);
        QTableWidgetItem *topCorner = new QTableWidgetItem("");
        mTransTable->setItem(0, 0, topCorner);
        topCorner->setFlags(Qt::ItemIsEnabled);
    }
    

    Then I have a QDockWidget called dockM in other class which inherit MainWindow class. I tried to put this custom widget into that dock and fill entire dock space. Seems not working as expected.

    void View:: DrawTopTable() {
        dockM->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
        dockM->setAllowedAreas(Qt::AllDockWidgetAreas);
        QVBoxLayout *layout = new QVBoxLayout;
        mTransTable = new TransTable(gNumOfTX, gNumOfRX);
        mTransTable->setLayout(layout);
        dockM->setWidget(mTransTable);
    }
    

    See below result 8bf29cd0-40d5-4d40-8dfc-a51140ed5a5d-image.png

    Wish someone could help :)

    jsulmJ 1 Reply Last reply
    0
    • D Dev-G

      Hi I am new to QT, below I created a custom table widget which inherit from QTableWidget.

      class TransTable : public QTableWidget {
          Q_OBJECT
      public:
          TransTable(int gNumOfTX , int gNumOfRX);
          ~TransTable();
      public slots:
          void UpdateTrans(QTableWidget *trans, int16_t *data);
      private:
          QTableWidget *mTransTable;
      };
      
      TransTable::TransTable(int gNumOfTX, int gNumOfRX)
      {
          mTransTable = new QTableWidget(this);
          mTransTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
      
          mTransTable->setRowCount(gNumOfTX + 2);
          mTransTable->setColumnCount(gNumOfRX + 2);
          int nRows = mTransTable->rowCount();
          int nCols = mTransTable->columnCount();
      
          mTransTable->setHorizontalHeaderLabels(headers);
          mTransTable->horizontalHeader()->setVisible(false);
          mTransTable->verticalHeader()->setVisible(false);
          QTableWidgetItem *topCorner = new QTableWidgetItem("");
          mTransTable->setItem(0, 0, topCorner);
          topCorner->setFlags(Qt::ItemIsEnabled);
      }
      

      Then I have a QDockWidget called dockM in other class which inherit MainWindow class. I tried to put this custom widget into that dock and fill entire dock space. Seems not working as expected.

      void View:: DrawTopTable() {
          dockM->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
          dockM->setAllowedAreas(Qt::AllDockWidgetAreas);
          QVBoxLayout *layout = new QVBoxLayout;
          mTransTable = new TransTable(gNumOfTX, gNumOfRX);
          mTransTable->setLayout(layout);
          dockM->setWidget(mTransTable);
      }
      

      See below result 8bf29cd0-40d5-4d40-8dfc-a51140ed5a5d-image.png

      Wish someone could help :)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Dev-G said in Custom Widget not taking entire space:

      mTransTable = new QTableWidget(this);

      Why do you create a QTableWidget instance if your class is a subclass of QTableWidget?!

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Dev-G said in Custom Widget not taking entire space:

        mTransTable = new QTableWidget(this);

        Why do you create a QTableWidget instance if your class is a subclass of QTableWidget?!

        D Offline
        D Offline
        Dev-G
        wrote on last edited by
        #3

        @jsulm Hi, my goal is trying to make this widget run on a separate thread other than the main UI thread. QTableWidget can fulfil my need, but it will be run on the main UI thread which I don't want it to. With that how should I set up my Widget?

        Chris KawaC 1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          As @jsulm said you have two tables here. From your TransTable remove the QTableWidget *mTransTable; member and just use this for the setup in the constructor. You also don't need that size policy set, since your table is the only item in the dock anyway, so it will take all the space.

          In the View:: DrawTopTable you don't need a layout set on a table. You're not using it anyway and dock widget already has a layout, so it will resize the table.

          1 Reply Last reply
          2
          • D Dev-G

            @jsulm Hi, my goal is trying to make this widget run on a separate thread other than the main UI thread. QTableWidget can fulfil my need, but it will be run on the main UI thread which I don't want it to. With that how should I set up my Widget?

            Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Dev-G said in Custom Widget not taking entire space:

            my goal is trying to make this widget run on a separate thread

            All UI code, including all the widget stuff has to run in the main thread. Qt does not allow multithreaded UI. you can run background tasks in separate threads, but UI is locked to main thread.

            D 1 Reply Last reply
            3
            • Chris KawaC Chris Kawa

              @Dev-G said in Custom Widget not taking entire space:

              my goal is trying to make this widget run on a separate thread

              All UI code, including all the widget stuff has to run in the main thread. Qt does not allow multithreaded UI. you can run background tasks in separate threads, but UI is locked to main thread.

              D Offline
              D Offline
              Dev-G
              wrote on last edited by
              #6

              @Chris-Kawa Thanks for your previous answer it is now working as expected!!! As for this response, I am in a situation like below: I have 2 sections which display data coming from same resource (basically the resource could be divided into two chunks) I measured each section run time as following 10ms filling data, 60ms drawing out result, 5ms, 30ms respectively. If only one thread can process UI that means 70ms + 35ms a total 105ms run time, ideally I prefer display the data seamlessly to reduce the total time to 70ms since 35ms is less than 70ms?

              jsulmJ 1 Reply Last reply
              0
              • D Dev-G has marked this topic as solved on
              • D Dev-G

                @Chris-Kawa Thanks for your previous answer it is now working as expected!!! As for this response, I am in a situation like below: I have 2 sections which display data coming from same resource (basically the resource could be divided into two chunks) I measured each section run time as following 10ms filling data, 60ms drawing out result, 5ms, 30ms respectively. If only one thread can process UI that means 70ms + 35ms a total 105ms run time, ideally I prefer display the data seamlessly to reduce the total time to 70ms since 35ms is less than 70ms?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Dev-G As said: UI may only be manipulated from the main (GUI) thread. Do all the work in your threads and then send the results via a signal to your UI. The UI can then update itself with the data it gets via signals from the threads.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                JonBJ 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Dev-G As said: UI may only be manipulated from the main (GUI) thread. Do all the work in your threads and then send the results via a signal to your UI. The UI can then update itself with the data it gets via signals from the threads.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @jsulm Please note the OP is discussing this in https://forum.qt.io/topic/146828/update-2-qtablewidgets-simultaneously-to-reduce-the-run-time.

                  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