Qt-interest Archive, March 2008
QTabWidget scrolling question
Message 1 in thread
Hi,
Im writing an application that uses tabs. Im new to Qt and thought to stick
with the standard widgets to keep it simple.
When there are more tabs than can be shown, two scoll arrows appear. So far
so good, but i would like that if user clicks one of them, that instead of
just scrolling the tabbar, it would make the next tab the current tab (eg
giving focus to another page instead of just moving the tabs. ) however, i
cant figure out how to catch the events from these buttons. QTabBar or
QTabWidget don't seem to have signals for those.
Is it possible and how?
thx
Message 2 in thread
really, nobody?
Message 3 in thread
Hi,
At a wild guess, I would look at deriving a class from QTabBar and
reimplementing the mousePressEvent() virtual function to do what you need.
HTH,
Sean
On Thursday 20 March 2008 12:57, Naja Melan wrote:
> really, nobody?
--
[ signature omitted ]
Message 4 in thread
Hi Naja,
First of all, please be sure to reply to the list and not to individuals. This
is so that list readers can get the benefits (if any) too.
On Thursday 20 March 2008 13:50, Naja Melan wrote:
> yes thanx, i was just digging up the source code for QTabBar, but it
> doesn't look very inviting to subclass... The scrollbuttons are obscured so
> far deep down in the code that so far the only trace i have been able to
> find of them is the boolean useScrollButtons...?
Hmmm, OK then. Looking at qtabbar.cpp shows this function:
void QTabBarPrivate::init()
{
Q_Q(QTabBar);
leftB = new QToolButton(q);
leftB->setAutoRepeat(true);
QObject::connect(leftB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs()));
leftB->hide();
rightB = new QToolButton(q);
rightB->setAutoRepeat(true);
QObject::connect(rightB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs()));
...
}
This means that the buttons are regular QToolButton objects and that they are
connected to the private slot void QTabBarPrivate::_q_scrollTabs(). It looks
as if most of the implementation is handled in the QTabBarPrivate class. It
will probably be easiest to patch this class so that within the
_q_scrollTabs() slot it gets the actual QTabBar to emit a signal e.g.
scrollButtonClicked() with maybe a parameter to indicate which button was
clicked. Your code can then react to this in the usual manner.
This is one of the downsides of using the pimpl approach (private d pointers),
in some cases it becomes a pain to derive a class to override a small aspect
of behaviour like this when the behaviour is in the private class. But hey,
that is the price for binary compatibility and you have the source code.
There may be a much easier way of doing this that I'm missing of course ;-)
HTH,
Sean
--
[ signature omitted ]
Message 5 in thread
ha,
thanx for the ideas, i will try that. That means i have to compile Qt myself
though, doesn't it. Then i have to link statically? im i right?
on the reply, my apologies, gmails hands off approach usually ends up
replying to the right adress...
naja
Message 6 in thread
Hi Naja,
On Thursday 20 March 2008 15:12, Naja Melan wrote:
> thanx for the ideas, i will try that. That means i have to compile Qt
> myself though, doesn't it. Then i have to link statically? im i right?
Partially. You'll need to rebuild QtGUI with your patch applied but there is
no need to link statically.
> on the reply, my apologies, gmails hands off approach usually ends up
> replying to the right adress...
No worries. It's easily done.
Good luck,
Sean
--
[ signature omitted ]
Message 7 in thread
Dear All
I need to show a symbol "*" on the right side of the name label of the
View (QGraphicsView), which i use as tab window through QTabWidget .When
the View is saved in the database , the "*" symbol should be removed(Like
normally every editor do).. Please give me some guidance to do this task..
Thanks alot for your help.
Rohit
--
[ signature omitted ]
Message 8 in thread
On torsdag den 20. Marts 2008, rohitj@xxxxxxxxxxxxxx wrote:
> Dear All
>
> I need to show a symbol "*" on the right side of the name label of the
> View (QGraphicsView), which i use as tab window through QTabWidget .When
> the View is saved in the database , the "*" symbol should be removed(Like
> normally every editor do).. Please give me some guidance to do this task..
You have to do a lot of manual work for this.
First of all, you need to subclass every single class used for objects in your
scene. Then you need to track down where the user manipulation leads to
changes in the scene. itemChangeEvent() is a good place to start, but it's
not enough. For text items you need to listen to the contentsChanged signal
of the embedded text document. And so on for all your items.
Bo.
--
[ signature omitted ]
Message 9 in thread
Dear All
I am facing a problem. I am creating a pop up menu in my Window. The sub
Menu of this main pop up menu are created at the run time. So i can not
hard code the number of sub menus in the code and also, can not hard code
the actions for the sub menus. So i am creating the subMenu at run time
by a loop function but how could i create Actions at run time!!! Based on
the user seletion of the subMenu , i have to call the slot function based
on common action. But how do i know...Which SubMenu the user had
selected????
Please suggest me some thing..
Thanks and Regards
Rohit
--
[ signature omitted ]
Message 10 in thread
Rohit,
You can create actions and add them to the menu at runtime. Then look
into using QSignalMapper with possibly an assigned integer id as the
mapping. Then all you need to do is keep track of what id goes with
whatever it pertains to (QMap<int, ...> is good for this).
Typically, mine looks something like this:
void populateMenu() {
for (int i = 0; i < listOfItems.size(); i++) {
Item *item = listOfItems.at(i);
QAction *a = new QAction(item->name(), menu);
menu->addAction(a);
signalMap->setMapping(a, item->id());
connect(a, SIGNAL(triggered()), signalMap, SLOT(map()));
mapOfItems.insert(item->id(), item);
}
}
Then elsewhere:
connect(
signalMap,
SIGNAL(mapped(int)),
this,
SLOT(menuItemClicked(int))
);
Then your slot gets the id of the item clicked as its argument, and you
can use your QMap to look up the item in the slot.
HTH,
Darrik
rohitj@xxxxxxxxxxxxxx wrote:
> Dear All
>
> I am facing a problem. I am creating a pop up menu in my Window. The sub
> Menu of this main pop up menu are created at the run time. So i can not
> hard code the number of sub menus in the code and also, can not hard code
> the actions for the sub menus. So i am creating the subMenu at run time
> by a loop function but how could i create Actions at run time!!! Based on
> the user seletion of the subMenu , i have to call the slot function based
> on common action. But how do i know...Which SubMenu the user had
> selected????
>
> Please suggest me some thing..
>
> Thanks and Regards
> Rohit
>
> --
> 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 11 in thread
Thanks alot for your replies..
Please, there is one more doubt.
Can i use same action for two diffenet menus but in the slot function of
the action triggering signal (Which is common for both menu as the same
action) , i should know which menu had triggered the action.
Thanks again....
Rohit
> Rohit,
>
> You can create actions and add them to the menu at runtime. Then look
> into using QSignalMapper with possibly an assigned integer id as the
> mapping. Then all you need to do is keep track of what id goes with
> whatever it pertains to (QMap<int, ...> is good for this).
>
> Typically, mine looks something like this:
>
> void populateMenu() {
> for (int i = 0; i < listOfItems.size(); i++) {
> Item *item = listOfItems.at(i);
> QAction *a = new QAction(item->name(), menu);
> menu->addAction(a);
> signalMap->setMapping(a, item->id());
> connect(a, SIGNAL(triggered()), signalMap, SLOT(map()));
> mapOfItems.insert(item->id(), item);
> }
> }
>
> Then elsewhere:
>
> connect(
> signalMap,
> SIGNAL(mapped(int)),
> this,
> SLOT(menuItemClicked(int))
> );
>
> Then your slot gets the id of the item clicked as its argument, and you
> can use your QMap to look up the item in the slot.
>
> HTH,
>
> Darrik
>
> rohitj@xxxxxxxxxxxxxx wrote:
>> Dear All
>>
>> I am facing a problem. I am creating a pop up menu in my Window. The sub
>> Menu of this main pop up menu are created at the run time. So i can not
>> hard code the number of sub menus in the code and also, can not hard
>> code
>> the actions for the sub menus. So i am creating the subMenu at run time
>> by a loop function but how could i create Actions at run time!!! Based
>> on
>> the user seletion of the subMenu , i have to call the slot function
>> based
>> on common action. But how do i know...Which SubMenu the user had
>> selected????
>>
>> Please suggest me some thing..
>>
>> Thanks and Regards
>> Rohit
>>
>> --
>> 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/
>>
>>
>
>
> --
> Darrik Mazey
> darrik@xxxxxxxxx
>
> --
> 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 12 in thread
Rohit,
I can't think of a way to do this off the top of my head. QSignalMapper
would have no way of distinguishing between them, as the triggered()
signal would originate from the same QAction. The same applies to
calling sender() in the slot. Is there a reason you can't create two
QActions? If you could do that, you could use QSignalMapper to identify
the menu the signal came from and still use a single slot.
Personally, my feeling is that if an action differs depending on which
menu it is called from, they should probably be two different actions,
but I don't know what exactly you're trying to do.
If you post a little more information, I might be able to help you come
up with a way to do what you're after. Without that, I'm at a loss.
Cheers,
Darrik
rohitj@xxxxxxxxxxxxxx wrote:
> Thanks alot for your replies..
>
> Please, there is one more doubt.
>
> Can i use same action for two diffenet menus but in the slot function of
> the action triggering signal (Which is common for both menu as the same
> action) , i should know which menu had triggered the action.
>
> Thanks again....
> Rohit
>
>
>> Rohit,
>>
>> You can create actions and add them to the menu at runtime. Then look
>> into using QSignalMapper with possibly an assigned integer id as the
>> mapping. Then all you need to do is keep track of what id goes with
>> whatever it pertains to (QMap<int, ...> is good for this).
>>
>> Typically, mine looks something like this:
>>
>> void populateMenu() {
>> for (int i = 0; i < listOfItems.size(); i++) {
>> Item *item = listOfItems.at(i);
>> QAction *a = new QAction(item->name(), menu);
>> menu->addAction(a);
>> signalMap->setMapping(a, item->id());
>> connect(a, SIGNAL(triggered()), signalMap, SLOT(map()));
>> mapOfItems.insert(item->id(), item);
>> }
>> }
>>
>> Then elsewhere:
>>
>> connect(
>> signalMap,
>> SIGNAL(mapped(int)),
>> this,
>> SLOT(menuItemClicked(int))
>> );
>>
>> Then your slot gets the id of the item clicked as its argument, and you
>> can use your QMap to look up the item in the slot.
>>
>> HTH,
>>
>> Darrik
>>
>> rohitj@xxxxxxxxxxxxxx wrote:
>>> Dear All
>>>
>>> I am facing a problem. I am creating a pop up menu in my Window. The sub
>>> Menu of this main pop up menu are created at the run time. So i can not
>>> hard code the number of sub menus in the code and also, can not hard
>>> code
>>> the actions for the sub menus. So i am creating the subMenu at run time
>>> by a loop function but how could i create Actions at run time!!! Based
>>> on
>>> the user seletion of the subMenu , i have to call the slot function
>>> based
>>> on common action. But how do i know...Which SubMenu the user had
>>> selected????
>>>
>>> Please suggest me some thing..
>>>
>>> Thanks and Regards
>>> Rohit
>>>
>>> --
>>> 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/
>>>
>>>
>>
>> --
>> Darrik Mazey
>> darrik@xxxxxxxxx
>>
>> --
>> 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/
>>
>
>
> --
> 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 ]