Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Table Header Column widths reset when calling setStyleSheet?
Forum Updated to NodeBB v4.3 + New Features

Table Header Column widths reset when calling setStyleSheet?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 186 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by
    #1

    I have an iTunes like app, with a sources list (Tree view) on the left, and a Tracks list (table view) on the right. User can select an item in the tree, and see the tracks for that "playlist"

    I have a custom "focus" drawing function that draws a "focus ring" around the currently targeted area, either Sources, Tracks, or the Search box (you can tab-key between focus areas, then use keyboard in that area)

    I handle the focus ring drawing using a custom stylesheet that i visually turn on or off.

    On Windows, Prior to 6.6.1 (maybe 6.5.?), and on mac (6.6.2), this works fine, but on the latest, it resets the columns to their default sizes.

    How can i get the columns to NOT resize, the way it used to work?

    class CFocusManager : public QObject {
    	typedef QObject		_inherited;
    	QBrowserWindow		*i_browserWindP;
    
    	#define		kBorder3pxSolid		" { border: 3px solid "
    
    	void		init()
    	{
    		QWidget			*searchEditP	= i_browserWindP->GetControl(BW_Control_SEARCH);
    		QWidget			*treeViewP		= i_browserWindP->GetControl(BW_Control_SOURCES);
    		QWidget			*tableViewP		= i_browserWindP->GetControl(BW_Control_TRACKS);
    		QWidgetVec		widgetVec;
    
    		widgetVec.push_back(treeViewP);
    		widgetVec.push_back(tableViewP);
    		widgetVec.push_back(searchEditP);
    
    		for (QWidget *widgetP: widgetVec) {
    
    			#if !_QT6_
    			if (OPT_WINOS || widgetP != searchEditP)
    			#endif
    			{
    				widgetP->installEventFilter(this);	//	focus manager
    			}
    
    			handleFocusEvent(
    				widgetP, QEvent::FocusOut, Qt::TabFocusReason, true);
    
    			if (widgetP == tableViewP) {
    				widgetP = widgetP->parentWidget();
    			}
    
    			widgetP = widgetP->parentWidget();
    			widgetP->layout()->setContentsMargins(0,0,0,0);
    		}
    	}
    
    	public:
    	void	handleFocusEvent(
    		QObject				*obj,
    		QEvent::Type		focusType,
    		Qt::FocusReason		focusReason,
    		bool				initB		= false,
    		bool				skip_paintB	= false)
    	{
    		if (focusReason != Qt::PopupFocusReason) {
    			QWidget				*widgetP(dynamic_cast<QWidget *>(obj));
    			CBrowserView_Table	*tableViewP(i_browserWindP->GetTableView());
    			bool				tableViewB(widgetP == tableViewP);
    
    			if (tableViewB) {
    				widgetP = widgetP->parentWidget();
    			}
    
    			widgetP = widgetP->parentWidget();
    
    			QString		parentNameStr(widgetP->objectName());
    			QString		borderStr("QFrame#" + parentNameStr);
    
    			borderStr += kBorder3pxSolid;
    
    			if (
    				focusType == QEvent::FocusIn
    				|| (
    					//	keep focus ring when app is in background
    					//	for only drag-drop.
    					gApp->IsDragging()
    					&& !i_browserWindP->isActiveWindow()
    				)
    			) {
    				borderStr += GetFocusRingColorStr();
    				borderStr += "; border-radius: 3px;";
    			} else {
    				Q_ASSERT(focusType == QEvent::FocusOut);
    				borderStr += "#00000000;";
    
    				if (initB) {
    					borderStr += " padding : 0px;";
    				}
    			}
    
    			borderStr += "}";
    
    			// the following call works fine on mac, and has worked on
    			// windows up until a recent release, in which it now always
    			// resets the column widths back to default. why?
    			widgetP->setStyleSheet(borderStr);
    
    			#if OPT_MACOS
    				widgetP->update();
    				new CMainThreadProc_RefreshControl(BW_Control_BROWSE_BUTTON);
    			#endif
    		}
    	}
    
    	//	------------------------------
    	public:
    	CFocusManager(QBrowserWindow *parentP) :
    		_inherited(parentP),
    		i_browserWindP(parentP)
    	{
    		init();
    	}
    
    	bool	eventFilter(QObject *objP, QEvent *eventP)
    	{
    		bool		handledB(false);
    
    		switch (eventP->type()) {
    
    			case QEvent::FocusIn:
    			case QEvent::FocusOut: {
    				QFocusEvent		*focusEventP(dynamic_cast<QFocusEvent *>(eventP));
    
    				handleFocusEvent(objP, eventP->type(), focusEventP->reason());
    				handledB = true;
    			} break;
    
    			default: {
    				handledB = _inherited::eventFilter(objP, eventP);
    			} break;
    		}
    
    		return handledB;
    	}
    };
    
    Christian EhrlicherC 1 Reply Last reply
    0
    • D davecotter

      I have an iTunes like app, with a sources list (Tree view) on the left, and a Tracks list (table view) on the right. User can select an item in the tree, and see the tracks for that "playlist"

      I have a custom "focus" drawing function that draws a "focus ring" around the currently targeted area, either Sources, Tracks, or the Search box (you can tab-key between focus areas, then use keyboard in that area)

      I handle the focus ring drawing using a custom stylesheet that i visually turn on or off.

      On Windows, Prior to 6.6.1 (maybe 6.5.?), and on mac (6.6.2), this works fine, but on the latest, it resets the columns to their default sizes.

      How can i get the columns to NOT resize, the way it used to work?

      class CFocusManager : public QObject {
      	typedef QObject		_inherited;
      	QBrowserWindow		*i_browserWindP;
      
      	#define		kBorder3pxSolid		" { border: 3px solid "
      
      	void		init()
      	{
      		QWidget			*searchEditP	= i_browserWindP->GetControl(BW_Control_SEARCH);
      		QWidget			*treeViewP		= i_browserWindP->GetControl(BW_Control_SOURCES);
      		QWidget			*tableViewP		= i_browserWindP->GetControl(BW_Control_TRACKS);
      		QWidgetVec		widgetVec;
      
      		widgetVec.push_back(treeViewP);
      		widgetVec.push_back(tableViewP);
      		widgetVec.push_back(searchEditP);
      
      		for (QWidget *widgetP: widgetVec) {
      
      			#if !_QT6_
      			if (OPT_WINOS || widgetP != searchEditP)
      			#endif
      			{
      				widgetP->installEventFilter(this);	//	focus manager
      			}
      
      			handleFocusEvent(
      				widgetP, QEvent::FocusOut, Qt::TabFocusReason, true);
      
      			if (widgetP == tableViewP) {
      				widgetP = widgetP->parentWidget();
      			}
      
      			widgetP = widgetP->parentWidget();
      			widgetP->layout()->setContentsMargins(0,0,0,0);
      		}
      	}
      
      	public:
      	void	handleFocusEvent(
      		QObject				*obj,
      		QEvent::Type		focusType,
      		Qt::FocusReason		focusReason,
      		bool				initB		= false,
      		bool				skip_paintB	= false)
      	{
      		if (focusReason != Qt::PopupFocusReason) {
      			QWidget				*widgetP(dynamic_cast<QWidget *>(obj));
      			CBrowserView_Table	*tableViewP(i_browserWindP->GetTableView());
      			bool				tableViewB(widgetP == tableViewP);
      
      			if (tableViewB) {
      				widgetP = widgetP->parentWidget();
      			}
      
      			widgetP = widgetP->parentWidget();
      
      			QString		parentNameStr(widgetP->objectName());
      			QString		borderStr("QFrame#" + parentNameStr);
      
      			borderStr += kBorder3pxSolid;
      
      			if (
      				focusType == QEvent::FocusIn
      				|| (
      					//	keep focus ring when app is in background
      					//	for only drag-drop.
      					gApp->IsDragging()
      					&& !i_browserWindP->isActiveWindow()
      				)
      			) {
      				borderStr += GetFocusRingColorStr();
      				borderStr += "; border-radius: 3px;";
      			} else {
      				Q_ASSERT(focusType == QEvent::FocusOut);
      				borderStr += "#00000000;";
      
      				if (initB) {
      					borderStr += " padding : 0px;";
      				}
      			}
      
      			borderStr += "}";
      
      			// the following call works fine on mac, and has worked on
      			// windows up until a recent release, in which it now always
      			// resets the column widths back to default. why?
      			widgetP->setStyleSheet(borderStr);
      
      			#if OPT_MACOS
      				widgetP->update();
      				new CMainThreadProc_RefreshControl(BW_Control_BROWSE_BUTTON);
      			#endif
      		}
      	}
      
      	//	------------------------------
      	public:
      	CFocusManager(QBrowserWindow *parentP) :
      		_inherited(parentP),
      		i_browserWindP(parentP)
      	{
      		init();
      	}
      
      	bool	eventFilter(QObject *objP, QEvent *eventP)
      	{
      		bool		handledB(false);
      
      		switch (eventP->type()) {
      
      			case QEvent::FocusIn:
      			case QEvent::FocusOut: {
      				QFocusEvent		*focusEventP(dynamic_cast<QFocusEvent *>(eventP));
      
      				handleFocusEvent(objP, eventP->type(), focusEventP->reason());
      				handledB = true;
      			} break;
      
      			default: {
      				handledB = _inherited::eventFilter(objP, eventP);
      			} break;
      		}
      
      		return handledB;
      	}
      };
      
      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      See https://bugreports.qt.io/browse/QTBUG-116013 and https://bugreports.qt.io/browse/QTBUG-122109

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • D davecotter has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved