This question already has answers here:
Increase check box size not its text using QCheckbox?
(3 answers)
Closed 4 years ago.
I have created a QCheckbox in QT Creator called 'override'.
I want to change the size of the actual checkbox, not the font of the text associated with it.
Is there a way of doing this?
Thanks for the help - I used this:
eyeChk = new QCheckBox("Eyes:");
_eyeChk->setStyleSheet("QCheckBox::indicator { width:150px; height: 150px;} QCheckBox::indicator::checked {image: url(/home/jvdglind/Downloads/280px-PNG_transparency_demonstration_2.png);}");
And just found sound decent default checkbox images.
Related
This question already has an answer here:
How to rename the program-name menu-label in a MacOS/X program?
(1 answer)
Closed 1 year ago.
I want to change the title of my Qt 5.15.0 application after it was executed.
For doing that, I'm using the setWindowTitle function of the QWidget class, like so:
setWindowTitle("My new window title");
Turns out the title is changed correctly on Windows but not on macOS. Here are the results:
Windows 10
macOS Catalina
You can see that in macOS the title is updated in the Window but not in the MenuBar (top) and in the Dock (bottom).
Is there a way to change all the titles on macOS once the app is running?
Edit
I managed to change the MenuBar title using the Objective-C code posted in this question (I just had to rename my .cpp file to .mm):
#import <AppKit/NSApplication.h>
#import <AppKit/NSMenu.h>
void setMenuProgramName(const char* newName)
{
NSMenu* mainMenu = [[NSApplication sharedApplication] mainMenu];
NSMenu* appMenu = [[mainMenu itemAtIndex:0] submenu];
[appMenu setTitle:[[NSString alloc] initWithUTF8String:newName]];
}
There's still the problem with changing the name in the Dock. There are some insights here and here but I couldn't make it work yet. It is said that I should "comment out NSApplicationMain in supporting files -> main.m" but I don't have that file and I don't know how could I do that using Qt. That's why I propose that the question be reopened since there's no solution for that yet.
Edit II
Apparently, as mentioned in this response, there's no way to change the title when you hover over the app icon in the Dock.
Alternatively, you can add a "badge" with the following code, but that's meant for notifications.
[[NSApp dockTile] setBadgeLabel:#"My custom text"]
It would be nice to know why this can't be changed - if it's because of a bad design decision or just a poorly developed framework.
you can like this:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QString windowTitle("New Title");
this->setWindowTitle(windowTitle);
}
This question already has answers here:
How do I make a clickable pin in SwiftUI's new Map view?
(2 answers)
Closed 1 year ago.
I'm building a swiftui app and am trying to implement a searchview for locations. I'm currently displaying the search results as annotations and want the user to be able to select them by tapping on them.
Is this possible, as the Annotations aren't views, I can't use a gesture modifier to solve the problem.
I found a way to use the system style. An apple developer forum thread made me aware that the image used for MapMarker is available as a system symbol/in sf symbols, so this is the implementation I came up with.
MapAnnotation(coordinate: result.coordinate) {
Button {
selectedDestination = result
} label: {
Image(systemName: result == selectedDestination ? "mappin.circle.fill" : "mappin.circle")
}
}
The size of the Image still has to be adjusted and the foreground color as well, but it works in principle.
This question already has answers here:
QLabel does not display in QWidget
(2 answers)
Closed 1 year ago.
I am working with a tableView and trying to implement some size styling.
The code:
// Setup table header items
Views::TeamTableHeaderView *header = new Views::TeamTableHeaderView(Qt::Horizontal);
ui->tableView->setHorizontalHeader(header);
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
ui->tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter | (Qt::Alignment)Qt::TextWordWrap);
for(auto& tableModel : entitlementLicenseModelMap)
{
tableModel->setHorizontalHeaderLabels({"PRODUCT", "TOTAL SEATS", "VALID UNTIL"});
}
This does not display any header on the table at all. When the call to setHorizontalHeader(header) is removed, the header displays fine. However, the header is too thin to render the text without cutting it off, hence I require a custom header (TeamTableHeaderView) to implement the sizeHint() to make it taller.
I have tried moving the setting of the header labels before and after, but the issue is that the header is just mot displaying at all, not even with the default "1" "2" "3" labels.
Some information:
This code executes after all of the data has been (successfully) populated in the tableModel.
The tableView is a bog standard QTableView
The TeamTableHeaderView is a custom type inherited from QHeaderView which only implements sizeHint(). Currently it just returns QHeaderView::sizeHint(). There is nothing special about this class yet.
The entitlementLicenseModelMap is a bit strange, but irrelevent to this question I believe. That whole for loop you can treat as just setting a table model. That table model is a QStandardItemModel.
Earlier in the code, a custom delegate is set to the model. However this delegate is not yet implemented. It is only set in order to later do some painting stuff. It inherits from QStyledItemDelegate, and only implements the paint function, which currently only saves the painter, calls QStyledItemDelegate::paint(...) and then restores the painter. I don't believe this delegate is relevant, but happy to be corrected.
To anyone else encountering this you just need to manually call:
header->setVisible(true)
Why this is the case when the header is normally visible by default when not otherwise specified.
This question already has an answer here:
CMFCButton with Vista Style
(1 answer)
Closed 2 years ago.
I have a CMFCMenuButton control on my dialog:
CONTROL "Lookup",IDC_MFCMENUBUTTON_LOOKUP_PUBLISHER,
"MfcMenuButton",WS_TABSTOP,106,254,45,14
I initialize it like this:
m_menuLookupPublisher.LoadMenu(IDR_MENU_LOOKUP_PUBLISHER);
m_btnLookupPublisher.m_hMenu = m_menuLookupPublisher.GetSubMenu(0)->GetSafeHmenu();
It works fine:
Update
I have added some extra code (based on answer provided to me):
m_menuLookupPublisher.LoadMenu(IDR_MENU_LOOKUP_PUBLISHER);
m_btnLookupPublisher.m_hMenu = m_menuLookupPublisher.GetSubMenu(0)->GetSafeHmenu();
m_btnLookupPublisher.m_nFlatStyle = CMFCButton::BUTTONSTYLE_SEMIFLAT;
m_btnLookupPublisher.m_bDrawFocus = FALSE;
This improves the look and feel of the button now, but it is still not 100% the same. Here is what it looks like now when it does not have focus:
It is just the way the border is displayed that is not correct. EnableWindowsThemeing is TRUE by default so I am not sure what else I need to do here.
What's annoying is that in the VS IDE it looks fine:
My question concerns the visual display of the menu button. The border looks different that the other buttons. Can it be made to look the same without too much work?
Update
I stumbled on this question which is now pointing me in the right direction. If I add this code:
m_btnLookupPublisher.ModifyStyle(BS_OWNERDRAW, 0, 0);
Then is draws the border correctly etc. but renders other aspects of the button useless so it is not a viable solution. But the remainder of the answer is what I needed:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
Are you talking about 3D look? Then you need to specify "flat" style BUTTONSTYLE_FLAT:
https://learn.microsoft.com/en-us/cpp/mfc/reference/cmfcbutton-class?view=msvc-160#m_nflatstyle
This question already has answers here:
Passing an argument to a slot
(6 answers)
Closed 6 years ago.
I'm new in Qt... I'm creating N buttons based on a JSON file. And I need to run a function/slot when a button is clicked and I need to know which buttton was pressed.
I tried:
QObject::connect(button, &QToolButton::clicked, this, &base::show_brands(json, type));
show_brands(json, type) is a function/slot...
but I can't send args like this...
How can I sent args to my function/slot? Or how can I run a function when a button is clicked?
You want to use QSignalMapper;
http://doc.qt.io/qt-5/qsignalmapper.html#details
This lets you send signals from a collection of objects to a single method which can identify the source object.