You are not logged in.

1

Sunday, August 12th 2007, 11:07pm

Problem with widget subclassing

Hello everyone. i have one problem:
i have MainWindow subclassing from QMainWindow. at this window i place custom widget for example named FlyMap and its class will be QFlyMap. from that class i can grab some data, for example position of cursor, when click.
also at mainwindow there are some labels. How can i set text to that labels from MousePressEvent event from this FlyMap.

so...
in QMainWindow:
QFlyMap* map = new QFlyMap(this);
map->setGeometry(400,100,400,400);
rightLay->addWidget(map);//QFlyMap.
...
l_ppm_nomer = new QLabel(s_ppm);
l_ppm_nomer->setGeometry(400,500,300,15);

in QFlyMap i have that function:
protected:
void QFlyMap::mousePressEvent(QMouseEvent *event)

how can i change text of some labels (l_ppm_nomer), that are from MainWindow class?
in the constructor of QFlyMap it sends QWidget* parent, may be from that i can reach those labels?

2

Sunday, August 12th 2007, 11:39pm

RE: Problem with widget subclassing

Yes you can reach MainWindow from parent() using casting
eg

qobject_cast<MainWindow * >(parent())->setMyLabelText(blabla)

assuming that your MainWindow class is providing setMyLabelText method.

Or you can modify QFlyMap's constructor so it can hold pointer to MainWindow.

3

Monday, August 13th 2007, 6:03am

RE: Problem with widget subclassing

doctor, big thanks! its works fine! i didn't knew about casting,but i tryed to send MainWindow obj vie QFlyMap constructor, but not a pointer:) so, thanks a lot!:)