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

Qt-interest Archive, June 2007
Can a QDockWidget have a layout?


Message 1 in thread

Hi all,

QDockWidget ::setWidget() works for one widget.
When I have more than one, I wish to add them in a layout, and then call 
setLayout()

    QHBoxLayout *hbox = new QHBoxLayout;
    hbox->addWidget(m_cmdEdit);
    hbox->addWidget(btnGo);

    QDockWidget *dw = new QDockWidget(tr("Command"), this);
    dw->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
//    dw->setWidget(m_cmdEdit); // works
    dw->setLayout(hbox); // does not work
    addDockWidget(Qt::BottomDockWidgetArea, dw);
    dw->setStatusTip(tr("Type in a command and press Go"));

I found setLayout() does not work here. So I wonder why not a 
QDockWidget can have a layout?

Thanks
Lingfa


--
 [ signature omitted ] 

Message 2 in thread

try creating a new to qwidget with only a single layout.. Then add youy current widgets to the layout.  Then add the top widget to the dock
--Scott
-----Original Message-----
From: Lingfa Yang <lingfa@xxxxxxx>
Date: Friday, Jun 15, 2007 8:17 am
Subject: Can a QDockWidget have a layout?
To: Qt Interest <qt-interest@xxxxxxxxxxxxx>

Hi all,
>
>QDockWidget ::setWidget() works for one widget.
>When I have more than one, I wish to add them in a layout, and then call setLayout()
>
>    QHBoxLayout *hbox = new QHBoxLayout;
>    hbox->addWidget(m_cmdEdit);
>    hbox->addWidget(btnGo);
>
>    QDockWidget *dw = new QDockWidget(tr("Command"), this);
>    dw->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
>//    dw->setWidget(m_cmdEdit); // works
>    dw->setLayout(hbox); // does not work
>    addDockWidget(Qt::BottomDockWidgetArea, dw);
>    dw->setStatusTip(tr("Type in a command and press Go"));
>
>I found setLayout() does not work here. So I wonder why not a QDockWidget can have a layout?
>
>Thanks
>Lingfa
>
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body. List archive and information: http://lists.trolltech.com/qt-interest/
>
>

--
 [ signature omitted ] 

Message 3 in thread

Scott Aron Bloom wrote:

>try creating a new to qwidget with only a single layout.. Then add youy current widgets to the layout.  Then add the top widget to the dock
>--Scott
>  
>
Yes, I did work around that way.
    QWidget *wi = new QWidget;
    wi->setLayout(hbox);

    QDockWidget *dw = new QDockWidget(tr("Command"), this);
    dw->setWidget(wi);
    addDockWidget(Qt::BottomDockWidgetArea, dw);
Just wonder why not directly. Thanks anyway.
Lingfa

--
 [ signature omitted ] 

Message 4 in thread

Hi,
is someone one can tell me where,I can find  in the doc how to know what 
item is under the mouse when user right click?
I want to show a contextmenu in a qtreeview.

contextmenu contents depend of the item under mouse.
I don't see how to translate from a viewport position to a qmodelindex 
or other any mvc info that help me to know for what item is the 
contextmenu wanted.
void QAbstractScrollArea::contextMenuEvent ( QContextMenuEvent 
<http://zorro/developpement/documentation/qt4.3.0/html/qcontextmenuevent.html> 
* /e/ )   [virtual protected]

thnak you for any tips.
Best regards,

Veronique.

Message 5 in thread

On 15.06.07 17:52:25, veronique.lefrere@xxxxxx wrote:
> is someone one can tell me where,I can find  in the doc how to know what item 
> is under the mouse when user right click?
> I want to show a contextmenu in a qtreeview.
> 
> contextmenu contents depend of the item under mouse.
> I don't see how to translate from a viewport position to a qmodelindex or other 
> any mvc info that help me to know for what item is the contextmenu wanted.
> void QAbstractScrollArea::contextMenuEvent ( QContextMenuEvent 
> <http://zorro/developpement/documentation/qt4.3.0/html/qcontextmenuevent.html> 
> * /e/ )   [virtual protected]

Read the QAbstractItemView documentation, the class contains indexAt().

Andreas

-- 
 [ signature omitted ] 

Message 6 in thread

Andreas Pakulat a écrit :

>On 15.06.07 17:52:25, veronique.lefrere@xxxxxx wrote:
>  
>
>>is someone one can tell me where,I can find  in the doc how to know what item 
>>is under the mouse when user right click?
>>I want to show a contextmenu in a qtreeview.
>>
>>contextmenu contents depend of the item under mouse.
>>I don't see how to translate from a viewport position to a qmodelindex or other 
>>any mvc info that help me to know for what item is the contextmenu wanted.
>>void QAbstractScrollArea::contextMenuEvent ( QContextMenuEvent 
>><http://zorro/developpement/documentation/qt4.3.0/html/qcontextmenuevent.html> 
>>* /e/ )   [virtual protected]
>>    
>>
>
>Read the QAbstractItemView documentation, the class contains indexAt().
>
>Andreas
>
>  
>
ok, thank's Andreas, it was the function I didn't see... :-[

have a nice weekend.
Veronique.



Message 7 in thread

On 15.06.07 11:31:57, Lingfa Yang wrote:
> Scott Aron Bloom wrote:
> 
> >try creating a new to qwidget with only a single layout.. Then add youy 
> >current widgets to the layout.  Then add the top widget to the dock
> >--Scott
> > 
> Yes, I did work around that way.

Its not a workaround, its "the right way". The QDockWidget has no widget
in its content area, so you need to add one. You can't have a layout
without a widget that the layout is applied to and applying a layout to
the QDockWidget itself doesn't make sense, as that would change its
titlebar, the buttons for closing and making it standalone, possibly the
frame and so on.

Andreas

-- 
 [ signature omitted ] 

Message 8 in thread

>Its not a workaround, its "the right way". The QDockWidget has no widget
>in its content area, so you need to add one. You can't have a layout
>without a widget that the layout is applied to and applying a layout to
>the QDockWidget itself doesn't make sense, 
>
I though dockWidget->setLayout(hbox) is a way to pass widges to the dock 
widget. But I may conceptually wrong.

>as that would change its
>titlebar, the buttons for closing and making it standalone, possibly the
>frame and so on.
>
>Andreas
>
>  
>
QDockWidget itself is a widget, and QWidget::setLayout() can apply to 
any widget.

Let’s assume hbox contains two widgets:
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addWidget(m_cmdEdit);
hbox->addWidget(btnGo);

the code “dockWidget->setLayout(hbox);” means give the two widgets to 
the dockWidget and arrange then in a horizontal box. Logically, I didn’t 
see anything wrong, just as a custom widget holder, which holder others.

I agree with you that “You can't have a layout without a widget“. But my 
hbox does have two widgets. By saying “The QDockWidget has no widget in 
its content area“ seems to me you consider QDockWidget as a layout.

I don’t understand setWidget() either. Very offten we don’t set a widget 
for a widget, instead, we setLayout() for.

Just some thought on the simple question. I wish I can learn more from 
you guy.
Lingfa


--
 [ signature omitted ] 

Message 9 in thread

> >Its not a workaround, its "the right way". The QDockWidget has no
widget
> >in its content area, so you need to add one. You can't have a layout
> >without a widget that the layout is applied to and applying a layout
to
> >the QDockWidget itself doesn't make sense,
> >
> I though dockWidget->setLayout(hbox) is a way to pass widges to the
dock
> widget. But I may conceptually wrong.
> 
> >as that would change its
> >titlebar, the buttons for closing and making it standalone, possibly
the
> >frame and so on.
> >
> >Andreas
> >
> >
> >
> QDockWidget itself is a widget, and QWidget::setLayout() can apply to
> any widget.
> 
> Let's assume hbox contains two widgets:
> QHBoxLayout *hbox = new QHBoxLayout;
> hbox->addWidget(m_cmdEdit);
> hbox->addWidget(btnGo);
> 
> the code "dockWidget->setLayout(hbox);" means give the two widgets to
> the dockWidget and arrange then in a horizontal box. Logically, I
didn't
> see anything wrong, just as a custom widget holder, which holder
others.
> 
> I agree with you that "You can't have a layout without a widget". But
my
> hbox does have two widgets. By saying "The QDockWidget has no widget
in
> its content area" seems to me you consider QDockWidget as a layout.
> 
> I don't understand setWidget() either. Very offten we don't set a
widget
> for a widget, instead, we setLayout() for.
> 
> Just some thought on the simple question. I wish I can learn more from
> you guy.
> Lingfa
> 

QDockWidget's setWidget is comparible to QMainWindows setCentralWidget

QDockWidget is widget with a predefined layout, just as a QMainWindow
is... There is 1 location for the user definable widget to go.

Scott

--
 [ signature omitted ] 

Message 10 in thread

>QDockWidget's setWidget is comparible to QMainWindows setCentralWidget
>
>QDockWidget is widget with a predefined layout, just as a QMainWindow
>is... There is 1 location for the user definable widget to go.
>
>Scott
>
>  
>
Good answer!

Now I understand because there is a predefined layout, it needn't set a 
layout, but add widget instead.

Thank you very much,
Lingfa



--
 [ signature omitted ] 

Message 11 in thread

Hello,
is it possible to to align a QIcon that is displayed in a QTableView cell 
using Qt::DecorationRole?? Qt::TextAlignment doesn't seem to work (the name 
already suggests it wont :) ).
I am trying to put my icon in to the horizontal center of the cell.

Thanks, Bastian

_________________________________________________________________
Haben Spinnen Ohren? Finden Sie es heraus ? mit dem MSN Suche Superquiz via  
http://www.msn-superquiz.de  Jetzt mitmachen und gewinnen!

--
 [ signature omitted ]