Welcome, Guest. Please login or register.

Author Topic: Qt oh god why  (Read 2896 times)

nimda

  • Full Member
  • ***
  • Posts: 161
  • Karma: +12/-2
    • View Profile
Qt oh god why
« on: July 29, 2013, 11:18:47 PM »
I have been trying for maybe the past hour to fix issue #248, to no avail.

Quick summary:
  • Send this message to an echo server: <b>Click Here</b>
  • Once it arrives, select "View HTML..."
  • Click in the bolded text
  • Select another message. This message is now bold.

Part of the problem (I think) is that the message textbox is not updated until after tableWidgetInboxItemClicked() (line 2781, __init__.py) returns, thus it is not trivial to clear the message before loading a new one. I'd rather not need to set a new function on a thread or timer to work around this.
Another solution would be to alter the font of the message text after loading it as setPlainText():
Code: [Select]
font = QFont()
self.ui.textEditInboxMessage.setFont(font)
...but this has seemingly no effect.

I believe this is a bug in Qt itself, but I could be wrong, and there must be a way to work around it, since it can be worked-around manually (details in the issue).



Help!
It's 90% UI from here. uPnP is a must.
BM-2DARKo7LcCvBiXyyabT5vNxgQ32pBqScuk

AyrA

  • BM-Bc7Rspa4zxAPy9PK26vmcyoovftipStp
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1261
  • Karma: +75/-7
  • bitmessage.ch and timeservice operator
    • View Profile
    • AyrAs Homepage
Re: Qt oh god why
« Reply #1 on: July 30, 2013, 01:43:52 AM »
If you CTRL+A into the textbox and delete all text, Formatting returns to default.
You probably just want your code to clear the textbox before you insert text again to solve it.
My Address: BM-Bc7Rspa4zxAPy9PK26vmcyoovftipStp
Bitmessage Time Service (Subscribe): BM-BcbRqcFFSQUUmXFKsPJgVQPSiFA3Xash
Support the Multipart Message Declaration Draft for Bitmessage: https://bitmessage.org/forum/index.php/topic,1553.0.html
Free Bitmessage to E-Mail Gateway: https://bitmessage.ch

nimda

  • Full Member
  • ***
  • Posts: 161
  • Karma: +12/-2
    • View Profile
Re: Qt oh god why
« Reply #2 on: July 30, 2013, 04:19:26 PM »
If you CTRL+A into the textbox and delete all text, Formatting returns to default.
You probably just want your code to clear the textbox before you insert text again to solve it.
Part of the problem (I think) is that the message textbox is not updated until after tableWidgetInboxItemClicked() (line 2781, __init__.py) returns, thus it is not trivial to clear the message before loading a new one. I'd rather not need to set a new function on a thread or timer to work around this.
It's 90% UI from here. uPnP is a must.
BM-2DARKo7LcCvBiXyyabT5vNxgQ32pBqScuk

AyrA

  • BM-Bc7Rspa4zxAPy9PK26vmcyoovftipStp
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1261
  • Karma: +75/-7
  • bitmessage.ch and timeservice operator
    • View Profile
    • AyrAs Homepage
Re: Qt oh god why
« Reply #3 on: July 30, 2013, 04:32:52 PM »
in this case, select all text in the application before applying the font.
My Address: BM-Bc7Rspa4zxAPy9PK26vmcyoovftipStp
Bitmessage Time Service (Subscribe): BM-BcbRqcFFSQUUmXFKsPJgVQPSiFA3Xash
Support the Multipart Message Declaration Draft for Bitmessage: https://bitmessage.org/forum/index.php/topic,1553.0.html
Free Bitmessage to E-Mail Gateway: https://bitmessage.ch

nimda

  • Full Member
  • ***
  • Posts: 161
  • Karma: +12/-2
    • View Profile
Re: Qt oh god why
« Reply #4 on: July 30, 2013, 05:09:13 PM »
in this case, select all text in the application before applying the font.
Huh? Like I said, changes aren't applied until after the function returns.
It's 90% UI from here. uPnP is a must.
BM-2DARKo7LcCvBiXyyabT5vNxgQ32pBqScuk

AyrA

  • BM-Bc7Rspa4zxAPy9PK26vmcyoovftipStp
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1261
  • Karma: +75/-7
  • bitmessage.ch and timeservice operator
    • View Profile
    • AyrAs Homepage
Re: Qt oh god why
« Reply #5 on: July 30, 2013, 05:14:06 PM »
I know this issue from RTF Textboxes in windows. If you set the font, you first need to select all text (even if the textbox is empty) and then applying the font. Also most controls have a "reset" function that returns it to its defaults. The QT Control probably has one too.
My Address: BM-Bc7Rspa4zxAPy9PK26vmcyoovftipStp
Bitmessage Time Service (Subscribe): BM-BcbRqcFFSQUUmXFKsPJgVQPSiFA3Xash
Support the Multipart Message Declaration Draft for Bitmessage: https://bitmessage.org/forum/index.php/topic,1553.0.html
Free Bitmessage to E-Mail Gateway: https://bitmessage.ch

zyrox

  • Full Member
  • ***
  • Posts: 103
  • Karma: +8/-2
    • View Profile
Re: Qt oh god why
« Reply #6 on: July 31, 2013, 06:08:28 AM »
in this case, select all text in the application before applying the font.
Huh? Like I said, changes aren't applied until after the function returns.
I'm not quite sure what the problem is but it sounds like you could use QApplication.processEvents() to have the GUI apply any recent changes before continuing
BM-2DAS9BAs92wLKajVy9DS1LFcDiey5dxp5c
libbitmessage | bitmessage-go

nimda

  • Full Member
  • ***
  • Posts: 161
  • Karma: +12/-2
    • View Profile
Re: Qt oh god why
« Reply #7 on: July 31, 2013, 10:17:33 PM »
I'm not quite sure what the problem is
Please follow the reproduction steps, they take less than 60 seconds and all they require is a working client on any OS.
Quote
but it sounds like you could use QApplication.processEvents() to have the GUI apply any recent changes before continuing
I'll try that, thanks.

Edit: the generic QApplication does not work:
Code: [Select]
    def tableWidgetInboxItemClicked(self):
        currentRow = self.ui.tableWidgetInbox.currentRow()
        if currentRow >= 0:
            fromAddress = str(self.ui.tableWidgetInbox.item(
                currentRow, 1).data(Qt.UserRole).toPyObject())
            self.ui.textEditInboxMessage.setPlainText(QString(""))
            QApplication.processEvents()
            time.sleep(2)
            # If we have received this message from either a broadcast address
            # or from someone in our address book, display as HTML
            if decodeAddress(fromAddress)[3] in shared.broadcastSendersForWhichImWatching or shared.isAddressInMyAddressBook(fromAddress):
                if len(self.ui.tableWidgetInbox.item(currentRow, 2).data(Qt.UserRole).toPyObject()) < 30000:
                    self.ui.textEditInboxMessage.setText(self.ui.tableWidgetInbox.item(
                        currentRow, 2).data(Qt.UserRole).toPyObject())  # Only show the first 30K characters
                else:
                    self.ui.textEditInboxMessage.setText(self.ui.tableWidgetInbox.item(currentRow, 2).data(Qt.UserRole).toPyObject()[
                                                         :30000] + '\n\nDisplay of the remainder of the message truncated because it is too long.')  # Only show the first 30K characters
            else:
                if len(self.ui.tableWidgetInbox.item(currentRow, 2).data(Qt.UserRole).toPyObject()) < 30000:
                    self.ui.textEditInboxMessage.setPlainText(self.ui.tableWidgetInbox.item(
                        currentRow, 2).data(Qt.UserRole).toPyObject())  # Only show the first 30K characters
                else:
                    self.ui.textEditInboxMessage.setPlainText(self.ui.tableWidgetInbox.item(currentRow, 2).data(Qt.UserRole).toPyObject()[
                                                              :30000] + '\n\nDisplay of the remainder of the message truncated because it is too long.')  # Only show the first 30K characters
            QApplication.processEvents()
As the 2 second sleep shows, QApplication.processEvents() doesn't have any effect (at least until the function returns): the text is not cleared for any visible length of time.

A QApplication instance app is present in the run and mainloop functions but this is not accessible to the function in question. I'd rather not change this either :/
« Last Edit: July 31, 2013, 11:19:47 PM by nimda »
It's 90% UI from here. uPnP is a must.
BM-2DARKo7LcCvBiXyyabT5vNxgQ32pBqScuk

zyrox

  • Full Member
  • ***
  • Posts: 103
  • Karma: +8/-2
    • View Profile
Re: Qt oh god why
« Reply #8 on: August 01, 2013, 01:09:29 PM »
Ok, I took a closer look at this problem and I made a pull request with a fix.
https://github.com/Bitmessage/PyBitmessage/pull/361

The pull request is just for convenience. If it doesn't fix the problem as you see it, just close it.
BM-2DAS9BAs92wLKajVy9DS1LFcDiey5dxp5c
libbitmessage | bitmessage-go