FAQ Database Discussion Community


Add custom attribute to QCheckBox widget

pyqt,attr,qwidget
I have (I think) a simple question but haven't had much luck trying to find an answer. Really new to pyqt! I am dynamically adding a number of QtGui.QCheckBox() widgets to a gridLayout based on a number of factors. My question is, how can I add a custom attr to...

Force QMainWindow to fit exact size of shown Text

qt,size,qwidget,qmainwindow
I try to build a frameless window with a single text label with changing text depending on chosen language and a boarder around it. This window should always have the smallest possible size. Here's the simple code without any configurations I tried so far. QMainWindow* clientIDDisplay = new QMainWindow(0, Qt::Window...

How can I ignore parent widget's tooltip in child widget in Qt?

c++,qt,tooltip,qwidget
I have a QWidget that a tooltip has been set on using setTooltip and within that widget, I have a child widget. The problem is that the child widget doesn't have a tooltip specified (i.e. "") but the tooltip of the parent widget is shown. If I do specify a...

Can you put QWidgets on the stack?

c++,qt,pointers,qwidget,qmessagebox
Backstory: I had some of my code reviewed, and I had made a local QMessageBox for displaying an error, and allocated it to the heap: if (getAutopilotList.error() == 0) { QMessageBox* error = new QMessageBox(0); error->setDetailedText(getAutopilotList.errorString()); error->setText("something"); error->setWindowTitle(tr("Error!")); error->show(); return; } The developer said: This pointer will leak, you are...

QWidgets as members or not?

c++,qt,constructor,member,qwidget
I just started to learn how to use Qt and I wonder if I should describe the Widgets (e.g. an array of Pushbuttons) in the QMainFrame class as private members or should I define them in the constructor of QMainFrame? What's the common implementation and what are the (dis)advantages of...

Can not overlay a transparent Qlabel on a QWidget that LibVLC uses

qt,transparency,qwidget,libvlc,qlabel
I have a question to LibVLC users that I have been struggling all day but couldn't come to a solution yet, so wanted to ask you for help. I have a Qt application that uses LibVLC to play videos, video streams. As you may know, LibVLC uses Qt widgets to...

Exact size of Application is size or sizeHint

qt,size,qwidget,sizehint
I have set the, setGeometry(0,0,1280,760); setMaximumSize(1280,760); setMinimumSize(1280,760); Now when I am printing size and sizeHint, I am getting size : QSize(1280, 760) sizeHint : QSize(970, 752) Which is exact size of my application, How can I change the size and size exactly to 1280X760 ?...

QWidget.paintevent() vs QLabel.setPixmap()

qt,qwidget,qlabel
I am trying to grab a widget and show it in another widget. Which one is less expensive? 1- using QWidget.paintevent() void MonitoringWidget::paintEvent(QPaintEvent *event) { if (m_mirrorWidget){ QPixmap mirrorPix = m_mirrorWidget->grab(); QPainter p(this); // p.drawPixmap(this->rect(),mirrorPix,mirrorPix.rect()); p.drawPixmap(ui->mirrorFrame->geometry(),mirrorPix,mirrorPix.rect()); update(); } return; } 2- QLabel.setPixmap()? QLabel mirrorLabel; QPixmap mirrorPix = m_mirrorWidget->grab(); mirrorLabel.setPixmap(mirrorPix )...

QtWidget Disable Margin for overlay widget

c++,qt,c++14,qwidget
My situation: I have a grid layout with n*n widgets inside. Additionally I place an overlay widget in the grid with position 0,0 and span n,n. Evertyhing fine with this, but there is a weird margin and I don't know what causes it... Has anyone an idea how i can...

maximized qmainwindow gets bigger then screen

qt,qwidget,qmainwindow,qlayout
I have QMainWindow with widgets, all the widgets have layout. But, when I play with the maximize and minimize QMainWindow buttons, I get the QMainWindow bigger then the screen size. Is there any property / flag that disable this issue ? Thanks....

Keeping the aspect ratio of a sub-classed QWidget during resize

c++,qt,qwidget
I'm creating a new widget, by subclassing the QWidget class. I'd like to be able to set a ratio (for its height and its width) for this widget, which will always be maintained. For this, I've always searched, using the Qt5 documentation, Google, and Stackoverflow. Obviously, I've found answers: in...

How to draw a Square between the text and the checkbox in QCheckBox

qt,qwidget,qcheckbox
I need to customize the QCheckbox like this: add a square between the checkbox and the text : So to do this, I inherit QCheckBox and override paintEvent(QPaintEvent*): void customCheckBox::paintEvent(QPaintEvent*){ QPainter p(this); QStyleOptionButton opt; initStyleOption(&opt); style()->drawControl(QStyle::CE_CheckBox,&opt,&p,this); QFontMetrics font= this->fontMetrics();// try to get pos by bounding rect of text, but it...

QT add widget(pushbutton, textEdit, labels) to QT Designer layout programatically [closed]

c++,qt,qwidget,qlabel
Is it possible to dynamically add widgets(Push Buttons, Labels etc), into a QT Designer generated central widget layout? How can it be done? Thank You!...

how to avoid memory leak in dynamically allocated widget

c++,qt,qwidget
I have to show a widgetA in a mainwindow without making it as a child of mainwindow . so if i dynamically allocate the memory space, it will trend to leak memory Widget *wid = new Widget; wid->show(); so i want to know how elegantly handle dynamic memory allocation of...

QTabWidget tab displays nothing in one of the tabs

c++,qt,user-interface,qwidget,qtablewidget
I am trying to create a gui that has a QTabWidget with multiple tabs. As a preliminary test I have created one that has two tabs using the same layouts. The first tab (Page 1) is blank but then the second one shows the QTableView I created. Both tabs were...

Square custom QWidgets inside QGridLayout inside QScrollArea

c++,qt,qwidget,qscrollarea,qgridlayout
I'm trying to lay out a grid of square custom (subclassed) QWidgets inside a QGridLayout and QScrollArea. The way I want it to work is choosing the number of QGridLayout columns and creating squares of the correct sizes. What I've tried doing already is Manually laying out/resizing the QWidgets but...

Qt Widgets FullScreen Margin

c++,qt,fullscreen,qwidget,qwebview
I want to create a program that loads google in literally full screen, so I achieved opening my qt program in full screen using w.showFullScreen(); and it works perfectly, however when I add the QWebView and set it to centralWidget like this: but when I run the program, I get...

QLayout aligning widget as wrong

c++,qt,qwidget,qlabel,qlayout
I have QLayout class which accept QLabel and align it as Qt::AlignRight in cell, Initially I think it is working(since the size of layout cell is exactly equal to size of pixmap), I have an event associated with the QLabel, ie when mousepressEvent occured the size of QLabel increase(size of...

QScrollArea not working as expected with QWidget and QVBoxLayout

c++,qt,qwidget,qscrollarea,qframe
So I have this QFrame which is the parent widget (represented by this in the code). In this widget, I want to place a QWidget at 10 px from top (and 10 px from bottom, as a result of which it will have a height of 140px, whereas parent is...

How to move the focus from a QLineEdit to a QTableView editable cell

qt,qwidget,qtableview,qlineedit,qt5.4
I am using a QMainWindow with few QLineEdits and with some QPushButtons in it. When the focus is in a QLineEdit (if I type something in the QLineEdit) and if I press the F5 key, I want to show a QDialog. That QDialog contains a QTableView. My question is, when...