PDA

View Full Version : statusbar



bhogasena
3rd February 2009, 12:07
hi,
i have created my own statusbar.in which i am displaying (x,y) coordinates as mouse moves. but as mouse moves it is over writing without clear message.
can any one help me for this problem

jpn
3rd February 2009, 12:23
Could you rephrase and clearly state what you have done so far? How does your status bar show the message etc.

ComaWhite
3rd February 2009, 12:29
Have you tried adding a label widget? And writing to that instead of the main statusbar label?

bhogasena
3rd February 2009, 13:02
hi,
in my mainwindow i have glwidget. in glwidget constructor i define my own statusbar(i.e statusbar1). i have written program for mousemoveevent() of glwidget. it give (x,y) coordinates. in mousemoveevent() i have written as

statusBar1->showMessage(str);

here str contains (x,y) coordinates.

now problem is first, when mouse point to one point it displays clearly in statusbar. but as mouse moves ,instead of clear previous status, it is displaying (overwriting) upon previous value. so i am not able to see clear values

jpn
3rd February 2009, 13:22
Could you show us the mouseMoveEvent() implementation? Are you sure you don't have multiple status bars? This works fine for me:


// main.cpp
#include <QtGui>

class Widget : public QWidget {
Q_OBJECT
public:
Widget(QWidget* parent = 0) : QWidget(parent) {
setMouseTracking(true);
}

signals:
void message(const QString& str);

protected:
void mouseMoveEvent(QMouseEvent* event) {
emit message(tr("(%1, %2)").arg(event->x()).arg(event->y()));
}
};

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QMainWindow window;
window.setCentralWidget(new Widget);
app.connect(window.centralWidget(), SIGNAL(message(QString)), window.statusBar(), SLOT(showMessage(QString)));
window.show();
return app.exec();
}

#include "main.moc"

bhogasena
3rd February 2009, 13:40
hi,
below is my mouse move event and GLWidget is central widget of my mainwindow.here i have one more problem i have setgeometry() for GLWidget as setGeometry(QRect(0,40,1015,515)). now if i setgeometry for statusbar below this i am not able to observe statusbar.if i setgeometry inside glwidget geometry it is overlapping my painting and has black color statusbar and white characters.




void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
QString str;
QString str1;
QString str2;
str.clear();
str1.clear();
str2.clear();


lastX=event->pos().x();
lastY=event->pos().y();
str1 = QString("x: %1 , ").arg(lastx, 0, 'E', 3);
str2 = QString(" y: %1").arg(lasty, 0, 'E', 3);
str=str1+str2;
statusBar1->setLayoutDirection(Qt::RightToLeft);
statusBar1->showMessage(str);


}

GLWidget::GLWidget(QWidget *parent):QGLWidget(parent)

{
setFocusPolicy (Qt::StrongFocus );
setFocus(Qt::OtherFocusReason);
setMouseTracking(true);
statusBar1=new QStatusBar(this);
statusBar1->setGeometry(QRect(0,475,1015,55));
label1=new QLabel(statusBar1);

QFont font("Helvetica", 12, QFont::Bold);
label1-> setFont(font);
label1-> setPalette(QPalette(QColor(225,22,45),QColor(23,12 ,34)));
label1->setGeometry(10,20,300,10);

statusBar1->setPalette(QPalette(QColor(225,22,45),QColor(23,12 ,34)));
statusBar1-> setFont(font);



// statusBar1->insertPermanentWidget(0,label1);
// window->setStatusBar(statusBar1);

}

bhogasena
3rd February 2009, 15:49
hi,
thank you for u r reply. now i am able to dispaly in mainwindow statusbar.
i have one more doubt.
suppose if i add Qlabel widget to the statusbar() then how can i dispaly same values in that?




Qlabel label1();
statusbar()->addpermanentwidget(label1);
i tried as, i put in slot as



statusbar()->label1->setText(QString);


but it is not working. could u plz clarify this one

Ginsengelf
3rd February 2009, 15:54
Hi, you have to store the pointer to label1 since QStatusBar provides no possibilities to access inserted widgets.

Ginsengelf