[Qt-interest] Display a message on the right corner
Ferenc Stelcz
ferenc at stelcz.hu
Fri Jun 12 15:22:36 CEST 2009
Sujan Dasmahapatra wrote:
> Friends
>
> Generally if we show a message on the status bar it's displayed on the
> left side. Can we display a message on the right side....I want to
> display the coordinates on the right side constantly as user moves
> mouse on the graphics view...is it possible...at the same time other
> conventional messages will appear on the left side as usually...
>
> Help me someone
You aren't learning anything from our suggestions on using the docs, are you?
Let's take the example code in $QTDIR/examples/mainwindows/mdi/mainwindow.cpp
for setting up a simple statusbar:
void MainWindow::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
}
Well this will display a message in the left corner.
Now, you want to add a widget that is visible all the time your mainwindow
exists. And it should be on the right side...... ... (lots of periods, because
we love it! lol)
So fire up Assistant and look for the keyword "statusBar". Read the docs, and
you'll find a method called "addPermanentWidget(QWidget *w, int stretch)". If
you don't understand it, use the Google translator to translate it to your
native language, it's a pretty good tool even for as a complex language as
hungarian. :P
If you are too lazy to do it yourself, here is an ugly but working example I
have written for you in about 5 minutes (included the time reading your post,
searching some example code, searching the docs and typing the code)
void MainWindow::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
QLabel* lbl = new QLabel(this);
lbl->setText("I am too lazy to read the documentation...");
statusBar()->addPermanentWidget(lbl,0);
}
Of course (as you will have noticed) *lbl* won't be visible from outside the
createStatusBar() method, so you'll have to tune it a bit.
HTH
--
Ferenc Stelcz
Junior Sofware Engineer
Banyan Technologies LLC.
__________ Information from ESET Smart Security, version of virus signature database 4150 (20090612) __________
The message was checked by ESET Smart Security.
http://www.eset.com
More information about the Qt-interest-old
mailing list