New KTabWidget

Jason Keirstead jason at keirstead.org
Sun Mar 2 05:01:48 GMT 2003


On March 2, 2003 12:51 am, Zack Rusin wrote:
> Oh, and the signals that you just mentioned shouldn't pass the widget of
> the stack or the tab because they are emitted for the buttons on the
> tab bar (in Konqueror I made the right one close the current tab and
> the left one open a new one). The actions for those buttons are not
> hardcoded in the widget so you can make it do whatever you want.
>
> Zack

Oh, I misinterperted the signals purpose.. In Kopete, I made right
clicking on the QTabBat emit a contextMenu( QWIdget* ) for the tab
that was right clicked. You don't need this for the left click of course
because that raises the tab and fires the currentChanged signal, making
it easy to get the clicked tab. But getting the right clicked tab is not easy
without re-implimenting QTabWidget and QTabBar, so I think it would be
a very good idea to add this in here while you are re-doing the widget.

Here is the relevent code I was using, pretty simple really

class KTabWidget : public QTabWidget
{
	...
	signals:
		/**
		* Fired when a context menu event occurs on a tab.
		* Usefull for a tab specfic popup menu.
		* @param target The widget within the tab the context menu was fired on
		* @param pos The position of the event
		*/
		void contextMenu( QWidget *target, const QPoint &pos );

class KTabBar : public QTabBar
{
	...
	signals:
		/**
		* Fired when a context menu event occurs on a tab.
		* Usefull for a tab specfic popup menu.
		* @param target The widget within the tab the context menu was fired on
		* @param pos The position of the event
		*/
		void contextMenu( QWidget *target, const QPoint &pos );
}

KTabBar::KTabBar( KTabWidget *parent ) : QTabBar( parent )
{
	connect( this, SIGNAL( contextMenu( QWidget *, const QPoint & ) ),
		parent, SIGNAL( contextMenu( QWidget *, const QPoint & ) ) );
}

void KTabBar::contextMenuEvent( QContextMenuEvent *e )
{
	QTab *tab = selectTab( e->pos() );
	if( tab )
	{
		KTabWidget *m_tabWidget = static_cast<KTabWidget*>( parent() );
		QWidget *targetTab = m_tabWidget->page( indexOf( tab->identifier() ) );
		emit( contextMenu( targetTab, mapToGlobal( e->pos() ) ) );
	}
}



-- 
Jason Keirstead, BCS
http://www.keirstead.org




More information about the kde-core-devel mailing list