Unsolved QWidget subclass does not appear on main window.
-
You have to add it to your layout. Best here is, since you're already using a ui file, to promote your widget in designer.
-
Hi
Its just invisible as the stylesheet is not applied.try adding
protected: virtual void paintEvent(QPaintEvent *event) override { QPainter p(this); p.drawRect(0, 0, width() - 1, height() - 1); }
and you see its there.
-
@Christian-Ehrlicher I added widget to mainwindow and promoted it to ToolBar, but still it isn't visible
-
@clostridium_difficile The move(50, 100) is useless / counter-productive. Please show us your current code.
-
@Christian-Ehrlicher current code? I showed you my current code in my first post in this topic and nothing changed. Widget has been promoted in Qt Designer. I moved toolbar to (50, 100), since I wanted to see what happens.
@mrjj i applied style sheet in linesetStyleSheet("background-color: #123456;");
-
@clostridium_difficile said in QWidget subclass does not appear on main window.:
I showed you my current code in my first post in this topic and nothing changed.
So now you're instantiating the class two times? One in the ui and one in the ctor? How should this ever work?
-
@Christian-Ehrlicher it it possible to have multiple instancens of the same widget type. I know what you mean – I didn't deleted ToolBar * toolBar; in Mainwindow – don't you? Apparently, it works for some reason – had two instances of this widget. I deleted it now, with initialization in constructor, but left only one instance, and nothing more has changed.
-
So now you can access your toolbar with 'ui->toolbar'? Please reimplement the paint event as suggested by @mrjj and fill your widget with e.g. a red color.
-
@Christian-Ehrlicher I've did it already. I see frame. Ok, thats what I wanted to achieve, but why setStyleSheet does not work?
-
@clostridium_difficile said in QWidget subclass does not appear on main window.:
but why setStyleSheet does not work?
I would guess because autoFillBackground is not set to true.