Table Header Column widths reset when calling setStyleSheet?
-
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; } };
-
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; } };
-