Unsolved Display a Personal Object (Draw a Circle) on QScrollArea & QGridLayOut
-
circle[i] = new ampel(this,1333,768); circle[i]->show(); circle[i]->resize(100,100);
don't works.
It could not be because the object handles another layer?regards
-
Impossible to say.
Maybe u cover it or maybe ur paint dont work.
You should test your custom widget in a test project where
NOTHING else could disturbed it.That way u know if it can even paint itself.
ampel * circle = new ampel(this,1333,768);
circle->show();
circle->resize(100,100);should be enough in test project.
Code do look fine as was as i can overview it.
-
@mrjj The next code works, but not into the QScrollArea, and invalidate it, the focus is blocked. (i have changed the object, for send the radius ).
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow){ ui->setupUi(this); setFixedSize(1333,768); const qint8 rad = 15; ampel *circle0[15]; for(qint8 i= 0; i < 15;i++){ //<-------here show 15 circles circle0[i] = new ampel(this,1333,768,rad); // circle[i]->show(); //not necesary // circle[i]->resize(100,100); //resize, do not work circle0[i]->updatePos(rad*i,rad*i); } QGridLayout *grid = new QGridLayout(); ampel *circle[15]; QLineEdit *channel[15], *timeOut[15], *canID[15]; for(qint8 i= 0; i < 15;i++){ circle[i] = new ampel(this,1333,768,5); //<--------here do not show nothing circle[i]->show(); circle[i]->resize(100,100); channel[i] = new QLineEdit(); timeOut[i] = new QLineEdit(); canID[i] = new QLineEdit(); grid->addWidget(circle[i],i,0); grid->addWidget(channel[i],i,1); grid->addWidget(timeOut[i],i,2); grid->addWidget(canID[i],i,3); } ui->scrollContents->setLayout(grid); // channel[2]->setText("prueba"); // timeOut[3]->setText("timeout"); }
-
hi
Ok, so now they show?
what u mean by focus is blocked? -
@mrjj That I can not scroll down the slider of QScrollArea.
The circles shown outside QScroll area, but not inside -
@yczo said:
grid->addWidget(circle[i],i,0);
but you add to grid?
That grid is in scrollarea?
How can it be outside?
The other objects u add, they are inside? -
@mrjj Yes, but don't shows. i think that the problem come from the way of generate the circle with absolute coordinates:
dc.drawEllipse(x,y,rad,rad);
x,y (absolute)
but i don't know another way, to make it.
Is There another method?Regards
-
@yczo
Hi it cant be absolute!
It will be relative to your self so the area
is 0,0, width, height !You draw inside. so u cannot ! use global x,y
you must move whole object! and it draws internal from 0,0so
dc.drawEllipse(x,y,rad,rad);
x,y can never be more than width / height :) -
@mrjj
We have a small misunderstanding, the new program draw twice, 15 circles out QScroll and should draw another 15 inside, but the last, don't make, just draw the first 15 created on mainwindowGreetings.
-
ok so it does draw and all is as you except ?
except the last is not inside the layout/scrollbox?Do u make these really big ?
new ampel(this,1333,768,5);is it 1333 x 768 ???
-
@mrjj 1333x768 is the size of layout where is permitted to draw
-
but if u must draw that big, it means u make the
Widget so big ?How big are the circle widgets?????
You can not draw outside the widget.
-
@mrjj Here is a hint: http://www.scriptscoop2.com/t/787129021050/qt-draw-inside-qscrollarea-in-a-qdialog.html
but i don't know how to:
Create another class which inherits QWidget. Override the paintEvent() method and to the painting you mention. Then, add the widget to the scroll area in your dialog. MyDialog::MyDialog() { QScrollArea *pScrl = new QScrollArea(this); pScrl->setWidget(new MyWidget(pScrl)); ... // use a layout to put the scroll area in the dialog } To really make it useful you will need to resize the MyWidget instance to the size of the circle that you want to draw.
Please can anybody help me? With a example?
Greetings