Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.3k Posts
  • How to remove weird graphic effects from widget?

    Solved
    5
    0 Votes
    5 Posts
    2k Views
    D
    @mpergand, First, I've removed the resizeEvent in mainwindow and RoundWidget, added your paintEvent in both of mainwindow and RoundWidget. In RoundWidget, ShadowWidth 2, 20 makes a huge gap in Windows 10. Added these: setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint); setAttribute(Qt::WA_TranslucentBackground); in mainwindow and with these changes, those round edges are smooth, as expected, BUT I still have the blinking effect: [image: 8146ce63-0985-437e-ac05-2a775f58883c.gif] maybe it's a windows 10 problem or because of multiple splitter. Log and Query are inside splitter1 and splitter2 contains Objects, splitter1 and Result. No idea why does it blink on that spot, that spot is the end point of splitter1. Thanks for that paintEvent that smoothened those round edges. EDIT Got that! that's because both of those splitters had that effect. I've to remove effect from splitter1 like this split1->setGraphicsEffect(0) and with that line in QueryWidget it's perfect: [image: db1e738b-6d0f-449b-85bc-ad7cf64cdcce.gif] Thanks once again.
  • qCamera

    Unsolved
    17
    0 Votes
    17 Posts
    2k Views
    Negar_mgN
    Thank you for your help I used Qt_5_15_2-Debug, but the part related to video recording is still inactive. I encountered this error while using this kit: Unsupported media type: "{32595559-0000-0010-8000-00AA00389B71}"
  • How do you add Dropshadow on QWidgets?

    Solved
    5
    0 Votes
    5 Posts
    1k Views
    D
    That's a tricky thing for noobs! First, in the toplevel widget (in my case QueryWidget) apply the effect like this: QueryWidget::QueryWidget(QWidget *parent) : QWidget(parent){ ... auto effect = new QGraphicsDropShadowEffect; effect->setBlurRadius(15); effect->setColor(Qt::black); effect->setOffset(0,0); setGraphicsEffect(effect); } in the child widgets (in my case ObjectsView, QueryView, QueryResultView and LogView) have something in setPalette and call setAutoFillBackground(true);. I've created another round corner widget and all child widgets inherits it: RoundWidget::RoundWidget(QWidget *parent) : QWidget(parent){ ... setPalette(QPalette(Qt::white)); setAutoFillBackground(true); ... } and finally subclass QSplitter and make the Palette of the handle transparent like this: Splitter::Splitter(Qt::Orientation o, QWidget *p) : QSplitter(o, p){} QSplitterHandle *Splitter::createHandle(){ auto handle = new QSplitterHandle(orientation(), this); handle->setPalette(QPalette(Qt::transparent)); return handle; } and use this Splitter in toplevel widget. You'll see something like this: [image: 7b632fff-8785-4c97-a922-6915aac8bb27.gif] I get some weird effect on the rounded edges and in some other places when I resize widgets with invisible handles.
  • Mingw32 Compiling an open source project "undefined referece to .. cxx11_basic_str"

    Unsolved
    8
    0 Votes
    8 Posts
    646 Views
    P
    Another update. I compiled with the flag -Wabi-tag, and got the following errors: warning: 'const string dlib::get_stack_trace()' inherits the "cxx11" ABI tag that 'const string' {aka 'const std::__cxx11::basic_string<char>'} (used in its return type) has [-Wabi-tag] C:/Qt6.2/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/basic_string.h:77:11: note: 'const string' {aka 'const std::__cxx11::basic_string<char>'} declared here class basic_string Even if I compile with the flags, -D_GLIBCXX_USE_CXX11_ABI=1 OR -D_GLIBCXX_USE_CXX11_ABI=0, same bugs occur. I am going to manually add #define D_GLIBCXX_USE_CXX11_ABI=1 to the header files and will post results. Official GCC comment on dual ABI: https://gcc.gnu.org/onlinedocs/gcc-5.2.0/libstdc++/manual/manual/using_dual_abi.html EDIT: Compiling the flags with either value results in the same error ("cx11").
  • QPalette doesn't apply correctly with QHBoxLayout

    Solved
    3
    0 Votes
    3 Posts
    244 Views
    V
    @Christian-Ehrlicher Good catch. I missed it. Thank you.
  • Qt Console App that uploads a file to Amazon AWS S3

    Unsolved
    2
    0 Votes
    2 Posts
    257 Views
    SGaistS
    Hi, Yes. You need to follow the API as described in the S3 documentation.
  • What class to use in Qt to use as a Streaming HTTP Client? Thanks for helping.

    Unsolved
    4
    0 Votes
    4 Posts
    298 Views
    SGaistS
    Yes indeed
  • Run the initialization everytime you start a dialog

    Solved
    11
    0 Votes
    11 Posts
    2k Views
    S
    Hi, so @mpergand and @JonB, it works perfectly. Thank you both for helping me :)
  • QListView in a QTabWidget tab - External Drop Not Working

    Solved
    19
    0 Votes
    19 Posts
    1k Views
    L
    @JonB Thank you for your suggestions. I found the problem. The dragDropMode attribute is not set, it defaults to NoDragDrop . But strangely, the default attribute does not work in Windows, and the default value NoDragDrop is OK in MacOS, Also the version of QT may be different or for other reasons For all that It's already working. Thank all
  • Searching a record and displaying data in QTableWidget

    Unsolved
    2
    0 Votes
    2 Posts
    156 Views
    M
    You might want use QSqlTableModel at QTableView instead. You can use QSqlTableModel::setFilter() to apply your WHERE clause.
  • QTableView : cell previous value keep showing when editing

    Solved
    8
    1 Votes
    8 Posts
    1k Views
    Christian EhrlicherC
    @natxo14 said in QTableView : cell previous value keep showing when editing: Is it worth opening it?? As I said I fixed it somewhen in between. So upgrade to latest 5.12.x will most likely fix it.
  • How set styleSheet for QLineEdit::placeholderText

    Unsolved
    6
    0 Votes
    6 Posts
    2k Views
    JonBJ
    @Mikeeeeee Oh for goodness sake. I already know that since you say it each time, I'm not stupid. I asked you what you want to be able to control about the placeholder text, in order to tell you whether/how it can be done by stylesheet. Since you refuse to answer I will just say QLineEdit[text=""] { color: red; } // and possibly you *may* need, I don't know connect(ui->lineEdit, &QLineEdit::textChanged, [=]{ style()->polish(ui->lineEdit); }); and now I'm out of this question.
  • 0 Votes
    3 Posts
    430 Views
    Z
    Thank you very much for replying! Please excuse me, it turns out that a modification I made caused the problem. The original version he provided me with seems to work perfectly, at least in isolation: There really was something missing. from PyQt5.QtWidgets import QApplication, QMainWindow, QTextEdit from PyQt5.QtGui import QCursor, QColor, QBrush, QTextLayout, QTextCharFormat, QTextCursor from PyQt5.Qt import QPoint app = QApplication([]) main_window = QMainWindow() class HighlightTextEdit(QTextEdit): highlightPos = -1, -1 def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setMouseTracking(True) self.highlightBlock = self.document().firstBlock() self.highlightFormat = QTextCharFormat() self.highlightFormat.setBackground( QBrush(QColor('#FFFF00'))) self.highlightFormat.setFontUnderline(True) self.document().contentsChanged.connect(self.highlight) def highlight(self, pos=None): if not self.toPlainText() or not self.isVisible(): return if pos is None: pos = self.mapFromGlobal(QCursor.pos()) cursor = self.cursorForPosition(pos) cursor.select(cursor.WordUnderCursor) start = cursor.selectionStart() end = cursor.selectionEnd() doc = self.document() block = doc.findBlock(start) # check if the mouse is actually inside the rectangle of the block blockRect = doc.documentLayout().blockBoundingRect(block) blockLayout = block.layout() if not pos in blockRect.translated(0, -self.verticalScrollBar().value()): # mouse is outside of the block, no highlight start = end = -1 startFromBlock = start - block.position() length = end - start if length: # ensure that the cursor is actually within the boundaries of the word textLine = blockLayout.lineForTextPosition(startFromBlock) endFromBlock = startFromBlock + length x, _ = textLine.cursorToX(endFromBlock) if pos.x() > blockRect.x() + x: start = end = -1 length = 0 # if the range is the same as the previous call, we can ignore it if self.highlightPos == (start, end): return # clear the previous highlighting self.highlightBlock.layout().clearFormats() self.highlightPos = start, end if length: # create a FormatRange for the highlight using the current format r = QTextLayout.FormatRange() r.start = startFromBlock r.length = length r.format = self.highlightFormat blockLayout.setFormats([r]) # notify that the document must be layed out (and repainted) again dirtyEnd = max( self.highlightBlock.position() + self.highlightBlock.length(), block.position() + block.length() ) dirtyStart = min(self.highlightBlock.position(), block.position()) doc.markContentsDirty(dirtyStart, dirtyEnd - dirtyStart) self.highlightBlock = block def viewportEvent(self, event): if event.type() == event.Leave: # disable highlight when leaving, using coordinates outside of the # viewport to ensure that highlighting is cleared self.highlight(QPoint(-1, -1)) elif event.type() == event.Enter: self.highlight() elif event.type() == event.MouseMove: if not event.buttons(): self.highlight(event.pos()) elif event.type() == event.MouseButtonRelease: self.highlight(event.pos()) return super().viewportEvent(event) text_edit = HighlightTextEdit() text_edit.setText("Óleo de motor Gás Racing Team Marca Vintage Sinais de metal Garage Man Cave Acessórios de decoração de parede Placas de metal retrô adesivos de parede") main_window.setCentralWidget(text_edit) main_window.show() text_edit.setFocus() app.exec() I'll just rollback to this one. Thanks a lot and sorry for the trouble! EDIT.: I came up with a better check for my use case: def check_if_mouse_position_is_over_text(self, position): if self.underMouse(): pos = position # create a QTextCursor at that position and select text text_cursor = self.cursorForPosition(pos) text_cursor.select(text_cursor.WordUnderCursor) selected_text = text_cursor.selectedText() start = text_cursor.selectionStart() end = text_cursor.selectionEnd() length = end - start text_cursor.clearSelection() block = text_cursor.block() block_rect = self.document().documentLayout().blockBoundingRect(block) # translate by the offset caused by the scroll bar block_rect.translate(0, -self.verticalScrollBar().value()) if length: new_cursor = self.textCursor() new_cursor.setPosition(start) self.setTextCursor(new_cursor) start_rect = self.cursorRect() start_point = self.mapToGlobal(start_rect.topLeft()) new_cursor.setPosition(end) self.setTextCursor(new_cursor) end_rect = self.cursorRect() end_point = self.mapToGlobal(end_rect.topLeft()) new_cursor.clearSelection() start_point_within_block = start - block.position() text_line = block.layout().lineForTextPosition(start_point_within_block) end_point_within_block = start_point_within_block + length x_end, _ = text_line.cursorToX(end_point_within_block) # extends the acceptable margin by 15 on both sides because Qt's falls slightly short of the real one error_margin = 15 if pos.x() + error_margin >= start_point.x() and pos.x() - error_margin <= end_point.x(): return True return False
  • QNetworkAccessManager keeps downloading wrong file...

    Solved qnetworkaccess qnetworkaccessm
    12
    0 Votes
    12 Posts
    2k Views
    JonBJ
    @Dariusz I still don't get how come you said the same URL worked to access the correct content from a web browser but not from QNetworkRequest, which was the important thing....
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • How to connect a signal with dbus signature 'a{sv}'?

    Unsolved
    1
    0 Votes
    1 Posts
    426 Views
    No one has replied
  • Could not set cursor on screen HDMI1: -13

    Unsolved
    1
    0 Votes
    1 Posts
    262 Views
    No one has replied
  • Get not scaled paint device on QWidget::paintEvent (ignoring devicePixelRatio)

    Unsolved
    5
    0 Votes
    5 Posts
    730 Views
    SGaistS
    Did you already saw the Scalability part ? QPainter uses the devicePixelRatio of the target.
  • How to detect whether mouseEvents take place over this or not?

    Solved
    6
    0 Votes
    6 Posts
    504 Views
    D
    @SGaist, excellent. Needed that changeEvent to change color on enabled/disabled and for hit test rect().contains(releaseEvent->pos()) looks like working perfectly.
  • How to include .svg file in qtopenglwidget

    Unsolved
    8
    0 Votes
    8 Posts
    840 Views
    SGaistS
    Then make a texture out of it and render it as part of your scene with the rest of your assets.