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

Wish someone could help :)
-
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

Wish someone could help :)
@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?!
-
@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?!
-
As @jsulm said you have two tables here. From your
TransTableremove theQTableWidget *mTransTable;member and just usethisfor 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:: DrawTopTableyou 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. -
@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?
@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.
-
@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.
@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?
-
D Dev-G has marked this topic as solved on
-
@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?
@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.
-
@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.