PDA

View Full Version : problems creating toolbar...(do see the attachment)!



sumit
27th August 2008, 12:52
Hi
i am a beginner in qt and working on a GUI application based on QT 4.4.i am facing some problems with embedding a combobox in toobar.It is working with QT 3 but not with qt4.I am attaching a snap here so that i can explain better.If you can see this snap, i have three problems creating these kind of toolbar.
1 there are tool buttons which are variable in size, and not arranged straight line (which is not a regular thing we do... right?) normally the buttons get placed in line with similar size.
2.I am not able to place the Qcombobox with other tool buttons.they are either overlapping or not getting inserted.
3.the lable below the toolbar,how I can set such a lable as QMainWindow in Qt4 doesnot have Setlable functionality.(which QT3 had...)

Any kind of help is worth needed.....

Thanks
- Sumit

wysota
27th August 2008, 22:22
Could you show us your code? I remember inserting a combobox into the toolbar in both Qt3 and Qt4 without any problems...

aamer4yu
28th August 2008, 05:47
Are you passing title in the constructor of QToolBar ??
QToolBar::QToolBar ( const QString & title, QWidget * parent = 0 ) ???

Also am not sure , but I guess the name of toolbar also depends on style,,, try running ur app with motif or some other style...

sumit
28th August 2008, 06:27
Thanxs.....
this is piece of my code ..... i am trying to create a toolabar with buttons (namedviewact is one of the buttons.)after that i will insert two comboboxes one right side of the button group and one below this set (buttton group and combobox..... in the same toolbar)....
snything that I am missing?




void HQApplication::CreateToolbars()
{
tools_toolbar = new QToolBar( "view", this);
optionwidget = new QWidget(tools_toolbar);
tools_toolbar->addAction(namedViewAct);

VisualStyleCombo = new QComboBox(optionwidget);
VisualStyleCombo->setInsertPolicy(QComboBox::InsertAfterCurrent);
VisualStyleCombo->addItem(*realisticIcon,tr("realistic"));

connect(VisualStyleCombo, SIGNAL(currentIndexChanged(int)),this, SLOT(VisualStyleChanged(int)));

QAction* qa = new QAction(VisualStyleCombo);
qa->setVisible(true);

tools_toolbar->addWidget(optionwidget);///////// OR
//tools_toolbar->insertWidget(namedViewAct,optionwidget);// i tried both
this->addToolBar(tools_toolbar);
}

Thanxs once again.........

wysota
28th August 2008, 13:42
What is the optionwidget? You insert a combobox into it but without any layout. If you instead insert the combobox directly into the toolbar or apply a layout on "optionwidget" you should get the desired result.

sumit
28th August 2008, 14:19
Hi guru
i managed to solve the problem with inserting Qcombobox in a toolbar with the same code above....just it was matter of restructuring i.e. putting things in right place.
now the big challenge before me is to get a view to toolbar in which I can insert tool buttons with variable QSize(for this i will attach another snap with this called variable_too_buttons.gif)
any help in things will worth helpful....

Thanxs for your help till now.................

sumit
28th August 2008, 14:23
Are you passing title in the constructor of QToolBar ??
QToolBar::QToolBar ( const QString & title, QWidget * parent = 0 ) ???

Also am not sure , but I guess the name of toolbar also depends on style,,, try running ur app with motif or some other style...





hi
i tried to use plastique and motif but .............. notthing worked can you please see my latest post..in that there is one attchment gif file.which explains my problem...
still thanxs anyways.....

aamer4yu
28th August 2008, 19:31
Referring to the last gif, doesnt the name look like QLabel !! ???
try adding QLabel in the QToolBar and see if u can get the desired effect. :)

And if you are referring to the 'Realtime' text, you can use QToolBar::setToolButtonStyle(Qt::ToolButtonTextUnd erIcon)

sumit
29th August 2008, 07:30
no i am talking about the nevigation label...the realtime label is not a problem i have implemented that but the toolbar label is not getting inserted in right place.also the can you see the different tool button size/icon .... seems like this is a tool bar style but somehow i am unable to find this.......can someone help in creating such a toolbar..

Thanx ....

wysota
31st August 2008, 22:06
What does your "Navigation" bar do?

You can get multiple rows of buttons if you insert a widget containing a layout of manually created buttons into the toolbar.

sumit
1st September 2008, 08:42
thanx...
i tried this (adding one widget with toolbuttons created inside it.) but my widget is not getting inserted(or visible?)on toolbar.QT says addwidget()-

Adds the given widget to the toolbar as the toolbar's last item.
If you add a QToolButton with this method, the tools bar's Qt::ToolButtonStyle will not be respected.
Note: You should use QAction::setVisible() to change the visibility of the widget. Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work.

I tried this also but unsuccessfully... can you help in this regard.

wysota
1st September 2008, 09:09
Can we see the code?

mchara
1st September 2008, 09:10
Hi, why not

QAction * QToolBar::addWidget ( QWidget * widget )

I had used it to embed QComboBox in toolbar and it worked fine.
This method is meant exactly for such cases!



Adds the given widget to the toolbar as the toolbar's last item.
If you add a QToolButton with this method, the tools bar's Qt::ToolButtonStyle will not be respected.

This one is important:


Note: You should use QAction::setVisible() to change the visibility of the widget. Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work.


So, insert your combobox directly without any layouts and additional widgets.
and try with combobox created withoud any parant,
addWidget () should deal with everything(reparenting, layout etc.) by itself, so simply do not disturb it.


theQuickFinder = new ElQuickFinder();
theFindToolBar->addWidget(theQuickFinder);

works fine in my app.

You can read also about related
QWidget * QToolBar::widgetForAction ( QAction * action ) const
method.

mchara
1st September 2008, 10:55
i've got mail that wysota has replied

There is not much of your code here... Would you care to show us what ElQuickFinder contains?
but i can't see the post - perhaps something went wrong...

anyway...
I can't post code of ElQuickFinder because it's part of commercial app with closed sources :(
but first - code of ElQuickFinder is highly application specific so i think it won't help anyway,
and second - i've placed emply class derived from combobox in toolbar and then i have started to writing quickfinder features and it worked well all the time with a number of different implementations from empty class to final implementation

i'm using qt 4.3.5 so perhaps something changed in qt 4.4


works fine also here (MdiWindowPrivate constructor in MdiWindow.cpp(GrEEn sources - see link in footnotes))


// ToolBars creation.
theFileToolBar = mainWindow->addToolBar(("File"));
theFileToolBar->setIconSize(QSize(24,24));
theFileToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
theFileToolBar->addAction(theFileOpen);
theFileToolBar->addAction(theFileSave);


theFileToolBar->setObjectName("FileToolBar");

theViewToolBar = mainWindow->addToolBar(("View"));
theViewToolBar->setObjectName("ViewToolBar");
theViewZoomWidget = new QComboBox();
theViewZoomWidget->addItem("10");
theViewZoomWidget->addItem("25");
theViewZoomWidget->addItem("50");
theViewZoomWidget->addItem("75");
theViewZoomWidget->addItem("100");
theViewZoomWidget->addItem("200");
theViewZoomWidget->addItem("300");
theViewZoomWidget->addItem("400");
theViewZoomWidget->addItem("FIT_TO_WINDOW");
theViewZoomWidget->addItem("FIT_TO_WIDTH");
theViewZoomWidget->addItem("FIT_TO_HEIGHT");
theViewZoomWidget->setEditable(true);
theViewZoomWidget->setEditText("");
theViewZoomWidget->setValidator(new QIntValidator(theViewZoomWidget));
theViewZoomWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
theViewZoomWidget->setCompleter(NULL);

connect(theViewZoomWidget,
SIGNAL(editTextChanged(const QString &)),
mainWindow,
SLOT(editTextChanged(const QString &)));
theZoomLabel = new QLabel(("Zoom:"));
theViewZoom = theViewToolBar->addWidget(theZoomLabel);
theViewZoom = theViewToolBar->addWidget(theViewZoomWidget);
theViewZoom = theViewToolBar->addWidget(new QLabel("%"));

wysota
1st September 2008, 11:00
You don't see my post because I deleted it as irrelevant.

sumit
10th September 2008, 11:23
thank you everybody .... with the above suggestions and some modification the problem is almost solved now....(though some i am battling with some label related issues!!!! )..
once again thanx for your help...