My widget doesn't show on the mainwindow. qt

Ashtaroth

in my program the senario is like this, user opens a xml file, the program reads it. Show the units and tests and when the user clicks on the desired test, the program needs to show its step. Since the number of steps always change i need to add the widget by code and delete them. But when i try to add a widget by code and set its position it doesn't show up on the main window. ( i am doing this with a seperate class just make things look neater)

Here is my sample code;

  void CStepPanel::addstep()
      {
           QLabel *label1 = new QLabel("step1");
           label1->move(450,50);


       }

Do you know doesnt it work ? And how can i do that. Since i am new to qt and programming i am having a hard time about this.

Nejat

Your widget should have a parent to be shown in an other widget or dialog. You should set a parent for the label. If you want it to be displayed on the main window then a pointer to your QMainWindow should be kept in the class CStepPanel (It could be assigned in the constructor of CStepPanel) :

QMainWindow * mainWindow;

And the addstep is like :

QLabel *label1 = new QLabel("step1");
label1->setParent(mainWindow);
label1->move(450,50);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Qt Creator doesn't load my custom widget plugin

From Dev

widget doesn't show notification

From Dev

Qt - mainwindow class object in another class doesn't work well

From Dev

(Qt) Read access error when attempting to use any function from another widget class on my MainWindow

From Dev

QCustomPlot/Widget doesn't show graph/update

From Dev

datetimepicker. widget doesn't show

From Dev

Qt Creator/Designer Program Doesn't Show?

From Dev

QtCreator 4.1.0 dosn't show webengineview(QT 5.7) for MainWindow form editor

From Dev

Qt creating new window from my mainwindow

From Dev

Why doesn't Qt see my slot?

From Dev

Qt - Why can't I trigger mousePressEvent for my custom button in MainWindow

From Dev

Qt.inputMethod.show () doesn't show any keyboard

From Dev

My QSqlQueryModel doesn't show data in the listview

From Dev

Why doesn't my wallpaper show up

From Dev

Profiler doesn't show my code

From Dev

My JFrame doesn't show anything

From Dev

HTML - Why doesn't my title show?

From Dev

color picker doesn't show in my code

From Dev

Why doesn't my box show?

From Dev

Why doesn't my wallpaper show up

From Dev

GridView doesn't show my datasource

From Dev

Why println doesn't show my array

From Dev

UILabel doesn't show up in my application

From Dev

Why doesn't my scope show with a directive?

From Dev

My circular slider doesn't show

From Dev

My RecyclerView ContextMenu doesn't show

From Dev

My toolbar doesn't show up in CardView

From Dev

Why doesn't a part of this tkinter Menu widget not show up?

From Dev

Django field widget doesn't show appropriate attribute