Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, April 2007
QLabel::setBuddy () not underscored?


Message 1 in thread

hi!

I'm on Qt 4.2.0. When I create a QLabel and a QLineEdit, call setBuddy() to make the shortcut work, 
I get the right behavior (QLineEdit recieves the focus), but the shortcut key is not underlined.
Hard for the user to know the shortcut then ;)

Have I done sth wrong?

cheers,
manu

ps: short example dialog:


====bugtest.h================================================

#ifndef BUGTEST_H
#define BUGTEST_H

#include <QDialog>

class QLabel;
class QLineEdit;


class BugTest : public QDialog
{
	Q_OBJECT
	
	public:
		BugTest(QWidget *parent = 0);
		~BugTest();
			
	private:
		void initComponents();
		
		QLabel *m_label;
		QLineEdit *m_lineEdit;
};


#endif

====bugtest.cpp==============================================

#include <QLabel>
#include <QLineEdit>
#include <QHBoxLayout>

#include "bugtest.h"

BugTest::BugTest(QWidget *parent)
{
	initComponents();
}

BugTest::~BugTest()
{
}

void BugTest::initComponents()
{
	m_label = new QLabel(tr("&Hello World"));
	m_lineEdit = new QLineEdit();
	
	m_label->setBuddy(m_lineEdit);
	
	QHBoxLayout *layout = new QHBoxLayout();
	layout->addWidget(m_label);
	layout->addWidget(m_lineEdit);
	
	setLayout(layout);
}

====main.cpp=================================================

#include <QApplication>

#include "bugtest.h"


int main( int argc, char* argv[] )
{
	QApplication app(argc, argv);
	
	BugTest *test = new BugTest();
	test->show();
	
	return app.exec();
}

--
 [ signature omitted ] 

Message 2 in thread

Hi,

> I'm on Qt 4.2.0. When I create a QLabel and a QLineEdit, call setBuddy() 
> to make the shortcut work, I get the right behavior (QLineEdit recieves 
> the focus), but the shortcut key is not underlined.
> Hard for the user to know the shortcut then ;)
> 
> Have I done sth wrong?

Nothing wrong as far as I can see.

This looks like a Qt 4.2 problem. It has been fixed in Qt 4.3.

Change BugTest::initComponents() to:

     QLabel *nameLabel = new QLabel(tr("N&ame:"));
     QLineEdit *nameLineEdit = new QLineEdit;
     nameLabel->setBuddy(nameLineEdit);
     QLabel *upgradeKeyLabel = new QLabel(tr("&Upgrade key:"));
     QLineEdit *upgradeKeyLineEdit = new QLineEdit;
     upgradeKeyLabel->setBuddy(upgradeKeyLineEdit);
     QGridLayout *layout = new QGridLayout;
     layout->addWidget(nameLabel, 0, 0);
     layout->addWidget(nameLineEdit, 0, 1);
     layout->addWidget(upgradeKeyLabel, 1, 0);
     layout->addWidget(upgradeKeyLineEdit, 1, 1);
     setLayout(layout);

You'll see that the first shortcut is not underlined, while the second is not. 
This can also be reproduced with Qt examples.

--
 [ signature omitted ] 

Message 3 in thread

thanks for your answer, Dimitri!
the underlining works with designer, though..

cheers,
manu


Dimitri wrote:
> Hi,
> 
>> I'm on Qt 4.2.0. When I create a QLabel and a QLineEdit, call 
>> setBuddy() to make the shortcut work, I get the right behavior 
>> (QLineEdit recieves the focus), but the shortcut key is not underlined.
>> Hard for the user to know the shortcut then ;)
>>
>> Have I done sth wrong?
> 
> Nothing wrong as far as I can see.
> 
> This looks like a Qt 4.2 problem. It has been fixed in Qt 4.3.
> 
> Change BugTest::initComponents() to:
> 
>     QLabel *nameLabel = new QLabel(tr("N&ame:"));
>     QLineEdit *nameLineEdit = new QLineEdit;
>     nameLabel->setBuddy(nameLineEdit);
>     QLabel *upgradeKeyLabel = new QLabel(tr("&Upgrade key:"));
>     QLineEdit *upgradeKeyLineEdit = new QLineEdit;
>     upgradeKeyLabel->setBuddy(upgradeKeyLineEdit);
>     QGridLayout *layout = new QGridLayout;
>     layout->addWidget(nameLabel, 0, 0);
>     layout->addWidget(nameLineEdit, 0, 1);
>     layout->addWidget(upgradeKeyLabel, 1, 0);
>     layout->addWidget(upgradeKeyLineEdit, 1, 1);
>     setLayout(layout);
> 
> You'll see that the first shortcut is not underlined, while the second 
> is not. This can also be reproduced with Qt examples.
> 
> -- 
> Dimitri

--
 [ signature omitted ] 

Message 4 in thread

Hi,

> the underlining works with designer, though..

I don't know, I've tried some Qt examples (examples/network/fortuneclient or 
examples/network/http) and they don't work either. How do you make this work 
in Designer?

In any case, if it works in Designer, just inspect the generated code: you 
have a workaround!

--
 [ signature omitted ] 

Message 5 in thread

ok, I was wrong.
It only worked in the designer-created dialog because I was opening 2 dialogs: the self-written one 
and the designer-created one. the first buddy-label in the dialog that is shown first doesn't have 
the underscore..

sorry for the confusion..

manu


Dimitri wrote:
> Hi,
> 
>> the underlining works with designer, though..
> 
> I don't know, I've tried some Qt examples 
> (examples/network/fortuneclient or examples/network/http) and they don't 
> work either. How do you make this work in Designer?
> 
> In any case, if it works in Designer, just inspect the generated code: 
> you have a workaround!
> 
> -- 
> Dimitri

--
 [ signature omitted ]